Please explain all the attributes of Magento block tag
<block type="catalog/product_featured" name="product_featured"
as="product_featured"
template="catalog/product/featured.phtml"></block>
<block type="catalog/product_featured" name="product_featured" template="catalog/product/featured.phtml">
<action method="setLimit"><limit>2</limit></action>
</block>
also why do we need two times the block tag
type = PHP file the template will look for the methods.. Here it is Mage_Catalog_Block_Product_Featured.php
name = Name of the block. It should be unique in the page.
as = Alias. Smaller form of name. It should be unique in it's parent block.
template = The template file (View) this block is attached to. You can call methods from block type inside this by using $this.. e.g. $this->getName()
name vs. as example:
<reference name="left">
<block type="block/type1" name="first_block" template="template1.phtml">
<block type="abc/abc" name="abc" as="common" template="abc.phtml"/>
</block>
<block type="block/type2" name="second_block" template="template2.phtml">
<block type="xyz/xyz" name="xyz" as="common" template="xyz.phtml"/>
</block>
</reference>
So, you can now call block name abc from first_block AND xyz from second_block as $this->getChildHtml('common');, but see both the blocks called will be different as per their calling parent.
Related
I am using IIS 8 and just learning about rewrites as I haven't ever written anything that cared about SEO.
I have the following rules that is working assuming the url looks like this: /survey/abc123/email
<rule name="Survey Rule" stopProcessing="true">
<match url="survey/([_0-9a-z-]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="survey.htm?var1={R:1}&var2={R:2}" />
</rule>
On the survey.htm page I have code that check for existence of var1 & var2 but in this rewrite if I have the url /survey/abc123 it doesn't obviously hit the Survey Rule. I have tried a couple of <conditions> but could find the right one.
I feel there must be a way to say
If {R:1} exists then var1={R:1} else var1=''
If {R:2} exists then var2={R:2} else var1=''
Ideally some type if loop. Is there any way to do this in a rewrite to that no matter how many / there are after survey, whether 0 or 10 it will always it the survey page?
I have looked at the rewrite map but I am not sure that solves this issue.
Edit
Possible urls that I would like to be rewritten:
/survey/abc123/
/survey.htm?var1=abc123
/survey/abc123/email/
/survey.htm?var1=abc123&var2=email
/survey/abc123/email/bob/
/survey.htm?var1=abc123&var2=email&var3=bob
/survey/abc123/email/bob/someOtherVar
/survey.htm?var1=abc123&var2=email&var3=bob&var4=someOtherVar
/result/1/
/result.htm?var1=1
/result/1/test#example.com
/result.htm?var1=1&var2=test#example.com
I would like the first item after the slash to be the page name and then each item after turned into the "query_string". I hope this makes a little more sense.
Short answer
You can't have exactly what you want with IIS rewrite only. And by what you want, i mean dynamically handling it with a loop.
Long answer
(1) With IIS rewrite only, this is the closest possible solution to your problem:
<rule name="Survey/Result Loop Rule" stopProcessing="true">
<match url="^(survey|result)/([^/]+)/(.*)$" />
<action type="Rewrite" url="/{R:1}/{R:3}?{R:2}={R:2}" appendQueryString="true" />
</rule>
<rule name="Survey/Result Default Rule" stopProcessing="true">
<match url="^(survey|result)/$" />
<action type="Rewrite" url="/{R:1}.htm" appendQueryString="true" />
</rule>
It will simulate a loop as long as the url contains parameters as subfolders, for both /survey/ and /result/. Then, it finally rewrites it to .htm page with query string appened. This is not possible to dynamicly generate query names such as var1 var2 etc by incrementing a number (at least, if a solution exists, it would be very tricky and heavy, because the rewrite engine is not made for this). In this example, both query names and values are the same, such as ?abc123=abc123&email=email.
(2) The cleanest way for this would be to delegate the job to the script:
<rule name="Survey/Result Default Rule" stopProcessing="true">
<match url="^(survey|result)/(.*)$" />
<action type="Rewrite" url="/{R:1}.htm?params={R:2}" />
</rule>
This rule rewrites, for instance, /survey/XXX/YYY/ZZZ/ to /survey.htm?params=XXX/YYY/ZZZ/. Since the job is delegated to the script, your htm files need to implement something like this (in pseudo code):
params = query_get('params');
// remove trailing slash in params if present
parameters = explode("/", query_get('params'))
for (i = 0; i < count(parameters); i++)
var{i+1} = parameters[i]
// var1 = parameters[0]
// var2 = parameters[1]
// var3 = parameters[2]
// and so on...
I think you get the idea.
In Struts 1, if the type attribute of the <action> tag has no value, what does it mean? Is there a default value for the type attribute that is used when it is not explicitly specified.
I'm basically trying to figure out what the following action does; as you can see it has no type attribute; it only has path and forward attributes:
<action path="/a/b/comp" forward="/components/d/my-comp.jsp">
</action>
The action that you have included above simply redirects from /a/b/comp.do to /components/d/my-comp.jsp. It is a shorthand for the following:
<action path="/a/b/comp"
parameter="/components/d/my-comp.jsp"
type="org.apache.struts.actions.ForwardAction">
</action>
So, for the action that you have included the type attribute is org.apache.struts.actions.ForwardAction.
I can't figure out how to write a rule that would solve this requirement :
Let's assume I have this request :
<Request>
<Attributes Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject">
<Content>
<Categories>
<Category name="cat1">
<CategoryValue>A</CategoryValue>
<CategoryValue>B</CategoryValue>
<CategoryValue>C</CategoryValue>
</Category>
<Category name="cat2">
<CategoryValue>B</CategoryValue>
<CategoryValue>E</CategoryValue>
<CategoryValue>F</CategoryValue>
</Category>
</Categories>
</Content>
</Attributes>
<Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource">
<Content>
<Categories>
<Category name="cat1">
<CategoryValue>A</CategoryValue>
</Category>
<Category name="cat2">
<CategoryValue>A</CategoryValue>
<CategoryValue>E</CategoryValue>
<CategoryValue>F</CategoryValue>
<CategoryValue>G</CategoryValue>
</Category>
</Categories>
</Content>
</Attributes>
</Request>
I want to write a policy that contains a rule with a Permit effect when for each of the Category elements of the resource, the subject has a Category with the same #name and if both of these Category elements has at least one common CategoryValue.
In this Example above :
Resource has "cat1" with "A" - Subject has "cat1" with one value that is A : Permit
Resource has "cat2" with "A", "E", "F", "G" - Subject has "cat2" with value E (or F) : Permit
Final result of the rule : Permit
My question is not on which functionId I should use, but how can I combine these conditions so that the rule behaves the way I described ? How to compare the GenericValue elements of nodes that has the same #name ?
I think I will have to use the string-at-least-one-member-of function between the values of the subject and resource "cat1", then between the subject and resource "cat2", but the real difficulty is that the PDP has no idea of the #name of the Category elements, so I can't hardcode it directly in the rule and I don't know how to select them in particular to perform the check.
Any idea on this ?
First of all, your request is invalid. You are missing some elements e.g.
ReturnPolicyIdList="true"
CombinedDecision="true"
Secondly, I would recommend you do not use XPath in XACML. It makes your policies hard to write (hence your question), hard to maintain, and hard to read (audit). It defeats the purpose of XACML in a way. Let the PEP do the heavy XML processing and send in attributes with attribute values rather than XML content.
In addition, you cannot control the iteration over the different elements / attribute values in the XML in XACML. I can implement your use case with a specific #name value but I cannot manage to do it over an array of values.
Assuming a single value, you would have to implement a condition as follows:
<xacml3:Rule RuleId="axiomatics-example-xacml30" Effect="Permit" xmlns:xacml3="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17">
<xacml3:Target/>
<xacml3:Condition >
<xacml3:Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-at-least-one-member-of">
<xacml3:AttributeSelector Path="/Categories/Category[#name='cat1']/CategoryValue/text()" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false" Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"/>
<xacml3:AttributeSelector Path="/Categories/Category[#name='cat1']/CategoryValue/text()" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"/>
</xacml3:Apply>
</xacml3:Condition>
</xacml3:Rule>
But you cannot really iterate over the different values
Have a tricky XPath issue that I can't quite seem to get. Let's say I have the following:
<content>
<body>
<block id="123">
<html>
<p align="left">Some text</p>
</html>
</block>
<block id="abc8383">
<html>
<p></p>
</html>
</block>
<block id="456">
<html>
<p><span>Some more text</span></p>
</html>
</block>
<block id="789">
<html>
<p></p>
</html>
</block>
<block id="012356">
<html>
<p class="finalBlock"><h3>content</h3><span>xyz</span></p>
</html>
</block>
</body>
</content>
I want to select all nodes above the element which has a p tag inside the xhtml with a "finalBlock" class, except for the ones that do not have context (node text - e.g. block id 789). However, this rule should only apply until the first node with content is encountered again - afterwards the empty elements should all be included. This means that the input above should produce the following output:
<content>
<body>
<block id="123">
<html>
<p align="left">Some text</p>
</html>
</block>
<block id="abc8383">
<html>
<p></p>
</html>
</block>
<block id="456">
<html>
<p><span>Some more text</span></p>
</html>
</block>
<block id="012356">
<html>
<p class="finalBlock"><h3>content</h3><span>xyz</span></p>
</html>
</block>
</body>
</content>
Where the element with an id of 789 was removed, but all others were kept. I've managed to craft the XPath query that excludes the block elements I want (empty ones), but am struggling with implementing the "between" rule. Any thoughts would be greatly appreciated!
Here's the expression excluding the empty block elements
//block[html/p]/html/p[normalize-space(.) != '']
This expression selects "the element which has a p tag inside the html, with a finalBlock class", which is <block id="012356">:
//*[html/p[#class='finalBlock']]
This one selects all the block nodes that precede it ("all nodes above" - which does not include the ancestor nodes):
//*[html/p[#class='finalBlock']]/preceding-sibling::*
You can add a predicate to restrict that to only the ones that have a non-empty p descendant:
//*[html/p[#class='finalBlock']]/preceding-sibling::*[descendant::p[string()]]
And the ones that have an empty p descendant, except the most recent one:
//*[html/p[#class='finalBlock']]/preceding-sibling::*[descendant::p[not(string())]][not(position() = 1)]
If you perform a union of the previous two expressions, you will obtain all the block nodes that satisfy the requirements you stated:
//*[html/p[#class='finalBlock']]/preceding-sibling::*[descendant::p[string()]]
| //*[html/p[#class='finalBlock']]/preceding-sibling::*[descendant::p[not(string())]][not(position() = 1)]
I have this chunk of XML:
<show name="Are We There Yet?">
<sid>24588</sid>
<network>TBS</network>
<title>The Kwandanegaba Children's Fund Episode</title>
<ep>03x31</ep>
<link>
http://www.tvrage.com/shows/id-24588/episodes/1065228407
</link>
</show>
I am trying to get "Are we there yet?" via Nokogiri. It is effectively the 'name' attribute of 'show'. I'm struggling to figure out how to parse this.
xml.at_css('show').value was my best guess but doesn't work.
You can use the following:
xml.at('//show/#name').text
which is XPath expression that returns the name attribute from the show element.
Use:
require 'nokogiri'
xml =<<EOT
<show name="Are We There Yet?">
<sid>24588</sid>
<network>TBS</network>
<title>The Kwandanegaba Children's Fund Episode</title>
<ep>03x31</ep>
<link>
http://www.tvrage.com/shows/id-24588/episodes/1065228407
</link>
</show>
EOT
xml = Nokogiri::XML(xml)
puts xml.at('show')['name']
=> Are We There Yet?
at accepts either CSS or XPath expressions, so feel free to use it for both. Use at_css or at_xpath if you know you need to declare the expression as CSS or XPath, respectively. at returns a Node, so you can simply reference the parameters of the node like you would a hash.