layout xml conditional of $_request params - magento

I understand it's in theory possible to use system config to determine the layout of a page (with the ifconfig option), is it possible to do something similar with variables passed by get or post? Or a cookie value for that matter?

This is not possible in standard Magento.
Depending on your use case there are some ways:
Implement an own XML attribute, for example <action method="foo" ifrequestvar="..."> The modle Aoe_LayoutConditions could give you a starting point:
Add an own layout handle. i.e. you check your condition that should be meet in normal PHP code (that works if the condition, i.e. the value of your $_REQUEST var is always the same) and then you can use this layout handle in the layout XML. You can add layout handles in an observer as shown in N98_CustomLayoutHandles.

Related

Augmenting config.allowedContent instead of overriding default value

The section entitled Advanced Content Filter guide in the CKEditor docs talks about how to set values for config.allowedContent. The documentation states that you can override the default value. No mention is made of how to obtain the default value and augment it.
For example, I want to allow script tags in addition to the default tags supported, as enhanced by any installed plugins. If I inspect config.allowedContent in the browser in the area where I set CKEditor config properties, I see that allowedContent is undefined. That tells m the default behavior is triggered by the value undefined, which is unfortunate.
How can this be done? I can think of the following approaches:
1) Somehow list the value of allowedContent on the console after initialization is complete. Not sure how to do that. Hard-code that value, plus script in the config section of my code. This is not the way I'd like to go forward.
2) Write a little plugin that merely adds script to allowedContent. Not sure what that would look like. This is a viable way forward.
3) Any other ideas?
I suppose that editor.config.extraAllowedContent is a remedy to your problem.
Note that CKEditor secures all <script> tags in your contents so included JavaScript is not executed (avoiding XSS). Anyway, for debugging purposes, allowedContent rules are stored in editor.filter.allowedContent during editor's lifetime.

Orchard CMS widget Display Type

I have a widget which is using a query to display details. Is it possible to specify the display type of the widget (the query is using Summary and all is displayed as i want) because the header of the widget has a display type of Detail and i want it to use summary so i can override the shape when i place it in different sections (mainly the header text), but when in the content zone i would want it to be details. I am using the bootstrap theme. So basically if i stick my widget any where other than content i want it to use summary
Hope this makes sense.
Thanks
Ah, we meet again.
Widgets are built and injected into the layout in a class called Orchard.Widgets.Filters.WidgetFilter. There doesn't appear to be any way to modify the display type used for a widget (the default WidgetFilter uses the default value of "Detail").
To get around this, you can use your own implementation of WidgetFilter. Copy the existing code into your own class, and add an [OrchardSuppressDependency("Orchard.Widgets.Filters.WidgetFilter")] attribute to your class. This will make sure that the existing WidgetFilter isn't used, and yours is.
If you read through the OnResultExecuting method, you'll see that right near the end there is a call to BuildDisplay. The second argument to this method can be a display type. You can check widgetPart.Record.Zone to see where the widget has been placed, and pass in different values for the displayType parameter accordingly.
I'm not sure if this is the most elegant way, but it's where I'd start. Perhaps someone else might have a neater solution.

Struts 2 - Conditionallly display elements on page based on validation errors

I'm looking into the fielderror tag for struts and was wondering if it was possible to conditionally show certain elements on the page based on whether or not there are any validation errors. I want to do something like this (which currently does not do what i want it to):
<s:fielderror>
This is a test link
<s:param>field1</s:param>
<s:param>field2</s:param>
<s:param>field2</s:param>
</s:fielderror>
I would like the anchor tag to show up ONLY if one of the fields referenced by the param tags is invalid. In other words, if something is invalid in this fielderror block, I would like to display some HTML. The way it is coded above, the anchor tag is always displayed.
I think I can certainly do this with jQuery, but i was wondering if there was a way to do this natively in Struts that perhaps I'm overlooking. I've tried looking at things like the label and title attribute, but nothing seems to be working.
thanks in advance!
~j
There's nothing out-of-the-box, at least not like the way you want it.
Personally, I find your construct quite counter-intuitive: it doesn't execute/render like it reads.
A few options: do it "manually", create a tag to do it, or do it outside of the view. All rely on using ValidationAware.getFieldErrors() to grab the map and do some minimal logic.
The manual approach would use <s:if> to check for the presence of fieldErrors['fieldName'] for each field. Wrapped up in a simplistic JSP-based custom tag would produce something like:
<if:fieldErrors for='field1, field2, field3'>
<a ...>
</if:fieldErrors>
IMO doing most of the work in Java is cleaner, and easier to test. This could mean doing all the work in the action (or utility) and exposing only a single flag to the view, or using a thin JSP-based tag to call the utility. Either way, it's easier to test outside of a container, and removes inappropriate view logic.

Magento - conditionals in layout files

Is it possible in Magento to conditionally add blocks into a layout xml file?
Im thinking along the lines of having an admin config option checkbox - if checked then a block needs to be added to the page and vice versa if not checked.
I could think of a way of doing this via code but not the actualy layout file system itself.
The ifconfig paramater can be used to conditionally call an action method
<action method="someBlockMethod" ifconfig="path/to/config"><param1>value</param></action>
The path/to/config path is passed to Mage::getStoreConfigFlag() to return a boolean.
I'd try using this in combination with the insert method
<action method="insert" ifconfig="path/to/config"><param>block_name</param></action>
The block with the name or alias of block_name will need to be already inserted into the layout object by other PHP or XML, so you may need to take additional steps to unset it from its original blocks after inserting it into your new block.
you can try this (i haven't tried it myself):
<action ifconfig='your/extension/active'

Setting access to remote in a cffunction includes the application.cfm page

When I set a cffunction's access to remote--so I can call it through AJAX--the call returns the HTML I have in my Application.cfm template.
Is there any way around this, or do I have to move the HTML out of Application.cfm?
This would be considered expected behavior. I'd suggest not outputting content within your Application.cfm. Consider using custom tags for wrapping your pages or better yet switch to using Application.cfc and use custom tags.

Resources