I've managed to get to the point where I understand how to move blocks from column to column in my Magento layouts: via specifying a "left" or "right" attribute in the <reference> tag. However, I don't understand how to change the order in which blocks appear. I've noticed that the "before" and "after" attributes of the <block> tag have something to do it with, but I'm not sure how they work. If I want to move a block from the top of its area to anywhere else in our page, what's the proper use and syntax for those attributes?
For example, I have a Category page and I have these blocks in it:
view.phtml
list.phtml
toolbar.phtml
... and so on.
I want to put my block anywhere within these blocks, or at the top of these blocks, or make all of these blocks show up inside another block. How can I use "before" and "after" to achieve this using my local.xml file?
Note: I can do it manually by inheriting their respective .xml files, but that's not a good solution to the problem as a whole.
before: Used to position the block before a block with the name specified in the value. If "-" value used the block is positioned before all other blocks of its level of block nesting.
after: Used to position the block after a block with the name specified in the value. If "-" value used the block is positioned after all other blocks of its level of block nesting.
Updated: examples from some random core layout updates:
<reference name="right">
<block type="catalog/product_compare_sidebar" before="cart_sidebar" name="catalog.compare.sidebar" template="catalog/product/compare/sidebar.phtml"/>
</reference>
<reference name="right">
<block type="catalog/product_list_related" name="catalog.product.related" before="-" template="catalog/product/list/related.phtml"/>
</reference>
Updated: I believe before and after work only in core/text_list and similar(descendant) blocks, i.e. blocks which just render blocks their nested blocks.
Related
I have a schema that is given to me (so I am not in position to make changes to it), and I am trying to generate the JAXB objects for it, and I get a naming conflict because of nested elements with same name.
I created bindings.xml to avoid the naming conflict, and it is working fine when I have a two level nesting (e.g. the XPath is something like this:
/A/Value/B/Value
So something like this solves the problem:
<jaxb:bindings
node="/xsd:schema/xsd:complexType[#name='A']
/xsd:complexType/xsd:sequence/xsd:element[#name='Value']
/xsd:complexType/xsd:sequence/xsd:element[#name='B']
/xsd:complexType/xsd:sequence/xsd:element[#name='Value']">
<jaxb:class name="InnerValue" />
</jaxb:bindings>
But now I have a three level nesting like this:
/A/Value/B/Value/C/Value
and I don't know how to define the bindings (whether I need two of them ) to avoid compilation errors.
Any help much appreciated
I think you have to customize your complex types, not elements. So attach your bindings to the corresponding xs:complexTypes. And yes, you will probably need two of them for inner B and C classes. I'd name them A_B and A_B_C, something like that.
See also jaxb:globalBindings/#localScoping='topLevel', might be useful.
I'd like to set a global variable such as SHOW_VIEW_FILES that when set to true, will output __FILE__ at the top of the view file (basically so we can see which files are used quickly rather than tracing code)? Was thinking that probably there is a string that gets appended to for view output and could just add it to the top there.
Or automatically inject a call to a method at the top of each view file? Is something like this already in existence - I think it should be like a one-liner.
Any ideas on how to get this done? Even better would be a way to suppress the normal output and output a tree structure (obviously more than a one-liner).
thx in advance
I came across something strange/weird when coding a spark file. I knew about Html.TextBoxFor, but i noticed my view was rendering it as pure text when i used this:
${Html.TextBoxFor(x => x.Name}}
But when i changed it to this it worked:
${Html.TextBoxFor(m => m.Name)}
the m here probably stands for Model as i've declared the mode like so at the top of the .spark file:
<viewdata model="Test.Models.RegisterViewModel" />
But x or m should be a delegate declaration or something. Could anyone tell me why x wont work in this case? Shouldnt it assume that everything i put in as x or m would be the model I've declared at the top of the page?
Copied from your question:
${Html.TextBoxFor(x => x.Name}}
${Html.TextBoxFor(m => m.Name)}
In the top one (using x) you have two closing curly braces instead of a parentheses and a brace.
In the second one (using m), you have the correct closing parentheses and brace. I can imagine that's why Spark rendered it as pure text in the top instance because it didn't recognise a code block there since you were missing a close paren.
There is no difference between the two . The variable is like a counter used in for ( a local variable that defines the common action taken upon all objects within the lambda expression.
The reason why that worked is probably the fact that you had an error in your previous code syntax, or you forgot to build
my 2 cents
Disclaimer:
I didn;t see the spark tag ... This answer is totally dedicated to the MVC aspect of the issue
I want to include a spark view in another spark view.
I've tried to use the include tag.
But it doesn't seem to support variables as part of the href attribute.
Eg.
<include href="_group_${groupData.Type}.spark" />
Does anyone know of any workaround to do this?
The <include> tag is part of the Spark language that gets parsed on the first pass and cannot include variables of its own because the view class file has not yet been generated for the variables to be evaluated. Using <include> is a means of including a static resource of some kind.
I think the thing you may be looking for is the <use import="myFile.spark"/> tag for including other Spark files, or you could just use Spark Partials built in. The problem however is that you're trying to have the included spark files dynamically determined at runtime which I don't think will be possible.
Is there any way you can pre-generate the views for each groupData.Type value using the pre-compilation ability in Spark?
The other option potentially (if you really do need these dynamic at runtime) is to create and maintain an InMemoryViewFolder instance and you can add "virtual" files to it as you pull them out of the database but you still won't get away with using variables inside any Spark language elements because variables "don't exist" at that point in the parsing/rendering pipeline.
Hope that helps,
Rob
I have a Path collection in Ant, and I need to loop through it in reverse order.
I use AntContrib's for loop, like this:
<for param="foo">
<path refid="bar" />
<sequential> ... </sequantial>
</for>
I need to loop through the elements of bar in reverse order. I can't change how the Path got created in the first place. I could always write a custom Ant task in Java, but my build currently runs without any custom tasks, and I'd rather avoid that for such a seemingly simple task.
Would Ant JavaScript be able to do this ? (and if so, how?)
Any help would be appreciated!
I think a "pure Ant" solution might be a bit contorted, but you could use a script task as you suggest.
This will set a property baz that contains the reverse of the path with reference id bar.
<script language="javascript"><![CDATA[
project.setProperty( "baz", project.getReference( "bar" )
.toString().split( ":" ).reverse( ).join( ":" ) );
]]></script>
Hopefully can be adapted to your precise needs.
Create a variable ("var" type in Ant Contrib) to store the path elements in the reverse order.
Then, use a for loop with your path as a nested path, use "equals" in a condition to check whether your variable is empty or not.
After that, if it is, just copy the value of the for loop parameter into your variable, otherwise copy the value of the for loop parameter into your variable followed by the delimiter and the value of variable (i.e make a concatenation).
Finally, you can just use the created variable in a for loop by using the "list" attribute and the "delimiter" attribute.
You can see what I mean in my own source code here.