Magnolia #cms.newBar - magnolia

I am creating some Magnolia templates and would like to know if any one has found a way to create a #cms.newBar and somehow use a node as the list of available paragraphs. The syntax is as below:
[#cms.newBar newLabel="Add Content" paragraph="template1, template2" /]
I want to use the node instead to avoid having to come back and add new templates when they are created.
I have seen the docs here and know that nothing is specified but wanted to see if anyone had found a way?

You can do several things, all boiling down to the same:
configure a string property containing "template1, template2", in your template definition. Assuming you're using Freemarker as the templating language, refer to it with ${def.thatProperty} (def references your template definition)
have your model class return that value: ${model.whatsCooking}, where your model class has a method String getWhatsCooking() which returns "template1, template2" (or whatever else you could come up with that decides what paragraphs should be available
STK does something similar to (1) - its template definitions contains Lists of "available" paragraphs, and its templates use some utility method to turn that into a comma-separated list, use with the new bar, so something like ${stk.toStringList(def.main.paragraphs)} (I can't recall the exact names and semantics, but you get the gist).
You should perhaps consider looking into STK for that, and a whole lot of things.
As for documentation, perhaps the templating guide and other docs will be more useful than the javadoc/tlddoc in this case.
HTH,

Related

2sxc List.Presentation in General View

I have an entity type "Post" and I would like to create a view that will show one random Post with a given category. I created a Data pipeline that grabs all posts and I created a view with ListPresentation = a "TemplateSettings" entity type that lets me choose categories.
I planned to use the Razor template to filter the items for those matching the categories in List.Presentation.Categories. But, I can't seem to reference List.Presentation.Categories. I get an error that System.Collections.Generic.List doesn't contain an entry for "Presentation". When I use #ListPresentation, the whole object in null... so #ListPresentation.Toolbar, etc. all throw errors, despite me having set a "Demo Item".
Can anybody see what would be wrong with this setup? How do I reference List Presentation stuff in Razor?
Thanks.
I figured this out... The direct thing seems to be "ListPresentation", but the snippets use "List.Presentation". Still, it wasn't working in my case because I was using a data query that didn't include the module data. So, I had to modify that query to include the module data as well as the full list of entities, regardless of the module. Then, I got the full list from one data stream, and the ListPresentation fields were available.
Note also that you can use ListContent.Presentation - that would be the newest, most consistent API which always places Presentation information as a property of the entity it's describing.

Executing an item in the package as a Dreamweaver Template

Does anybody know if it is possible in a compound template to use a string item in the package and execute it as if were a dreamweaver template? And whether you apply the same method to other mediators (like razor)?
Thanks
Mark
I suspect this is not possible.
Package.EvaluateExpression may be useful, but as the name suggests it'll only work on expressions, not large snippets of code with embedded expressions (i.e. TEL)
Engine.GetMediator expects a Template and returns the appropriate Mediator for it. Your problem then is that the IMediator interface only defines the Transform method, which requires an Engine, a Template and a Package.
I can't think of any elegant ways around these. Maybe write your own Mediator, but that would still expect a Package, not a string, so you'd have to first store the string based Item from another TBB.
My advice: Sounds like you need to go back to the drawing board and find an alternative solution to your problem.
I'm afraid that won't be possible on just any item in the Package, since the Engine expects Templates to be based on Tridion items.
If your Template Item is based on a Tridion Item you can probably get pretty far by starting at the Engine.GetMediator method. If it isn't, you'll have to find some way to turn it into a valid Template object.
Template template = ...
IMediator mediator = engine.GetMediator(template);
mediator.Transform(engine, template, package);
When I have to create a Component object from a Tridion-based Item in the Package, I normally do something like this:
Component component = new Component(item.GetAsXmlDocument().DocumentElement,
engine.GetSession);
I haven't tried, but expect that you can do the same for a Template - given that you start with a valid Item from the Package representing a Template to begin with. You can probably clone the XML from an existing Item or find some other way to fake it.
If you get this to work, it will work across all registered template types. The Engine provides no special treatment for the types that come with Tridion.

Accessing an object's workflow state in collective.easytemplate

I would like to use collective.easytemplate to generate templated emails (for content rules). However, I am not sure if it can output an objects workflow state. Anybody know if it is possible and how it is done?
Thanks.
You can, it is possible, and one way is to use the portal_workflow tool e.g. from parts/omelette/plone/app/contentrules/tests/test_action_workflow.py:
self.assertEquals('published',
self.portal.portal_workflow.getInfoFor(self.folder.d1, 'review_state'))
More generally, something like:
context.portal_workflow.getInfoFor(context, 'review_state')
in a page template should work. Or use the portal_catalog as Spanky suggests e.g. if "obj" is a catalog "brain" (i.e. part of a result set from a catalog search) then:
obj.review_state
should work.
The portal_catalog also has an index of the workflow's Review State, so if you don't already have the object you're working on (e.g. context ≠ the object) you could use the catalog, look up the object and get the review state from the resulting "brains" object.
Apparently there are ALSO browser view methods available to you as well, and I notice that one of them is workflow_state. See:
http://plone.org/documentation/manual/theme-reference/page/otherinfo

Utility class or Common class in asp.net

Do anyone knows about the class which has the common function which we generally use while developing web application. I have no idea what you may call it, it may be the utility class or common function class. Just for reference, this class can have some common function like:
Generate Random number
Get the file path
Get the concatinated string
To check the string null or empty
Find controls
The idea is to have the collection of function which we generally use while developing asp.net application.
No idea what you are really asking, but there already are ready-made methods for the tasks you write in various library classes:
Random.Next() or RNGCryptoServiceProvider.GetBytes()
Path.GetDirectoryName()
String.Concat() or simply x + y
String.IsNullOrEmpty()
Control.FindControl()
Gotta love the intarwebs - An endless stream of people eager to criticize your style while completely failing to address the obvious "toy" question. ;)
Chris, you want to inherit all your individual page classes from a common base class, which itself inherits from Page. That will let you put all your shared functionality in a single place, without needing to duplicate it in every page.
In your example it looks like utility class - it is set of static functions.
But I think that you should group it in few different classes rather than put all methods in one class - you shouldn't mix UI functions(6) with string functions(3,4), IO functions (2) and math(1).
As Mormegil said - those functions exists in framework, but if you want to create your own implementations then I think that for part of your function the best solution is to create extension method.

Panel page URL - Need to access named arguments

I have a Panel page, which I have given a path of: books/travel-books/%city/%country/%page. The help text underneath the field says "The URL path to get to this page. You may create named placeholders for variable parts of the path by using %name for required elements and !name for optional elements. For example: "node/%node/foo", "forum/%forum" or "dashboard/!input". These named placeholders can be turned into contexts on the arguments form.", so I have named my arguments appropriately.
So now in my code, I need to get the values of those arguments. I've seen arg(0), but that requires me knowing which index the argument has. Is there anyway to access it by the name I gave it in the path? Something like arg('city')??
The reason being, that I need to have similar path arguments on many pages, and need to access the values of these in my module. But the arguments may be in different places for another page. For instance, another page might be at: flights/%city/%country. Then I want to access the city argument within the same function, but it is at a different index.
Can anyone help?
you can check for arg(0) first, see whether it is 'books', 'flights', whatever... then associate names accordingly. do it as a helper function in a custom module and call it before referencing (wherever you're referencing it).
The text that you quoted from the panels help text is referring to what panels call context.
Panels
Panels has a great use if you want to aware of what context a certain piece of content is being viewed. Fx if you had several shops with different products, you might want to control which blocks in a sidebar would be displayed, based on the shop that the product belonged to.
This is essential what context is in panels and what the named placeholdes are used for. You can be default add different kinds of context, fx nodes, users, taxonomy terms. You can then use the different pieces of context if various ways.
If panels default options is not enough, you can also create your own plugins to panels to make it handle your special cases. But it requires a lot of time to learn how panels work.
Other solutions
Using panels might not be the easiest option for you, it depends what you are aiming for. But if you don't need to make pages that is aware of the context, this would probably be a lot easier to do with views and theming. Views can handle arguments in urls very well, and it is a lot simpler to both style and configure.
In Drupal 7 you can get the arguments from hook_content_type_render
function <your plugin name>_content_type_render($subtype, $conf, $panel_args, $context) {
$block = new StdClass;
$block->title = t('test');
$block->content = 'test panel arg: '.$panel_args[0];
return $block;
}
Custom panel tutorial

Resources