I am attempting to render a single line of text prior to a Link list in the footer. Creating a template file to do this seems to be a waste of resources for this task. As I understood it, I could output text with a Magento\Framework\View\Element\Text block in the layout.
XML
<referenceContainer name="footer">
<container name="footer.column.about_us" htmlTag="div" htmlClass="column about-us" before="-">
<container name="column.about_us.label" htmlTag="div" htmlClass="label">
<block class="Magento\Framework\View\Element\Text" name="about_us.label">
<arguments>
<argument name="data" xsi:type="array">
<item name="text" xsi:type="string">About Us</item>
</argument>
</arguments>
</block>
</container>
<block class="Magento\Framework\View\Element\Html\Links" name="footer_links.about_us">
<arguments>
<argument name="css_class" xsi:type="string">footer links</argument>
</arguments>
</block>
</container>
</referenceContainer>
The preceding does not output anything, and I am unsure whether this is unsupported, if I'm just doing it wrong, or if there is another more proper method to accomplish this.
To be clear, what I'm currently seeing is:
<div class="column about-us">
<ul class="footer links">...</ul>
</div>
when I want to see:
<div class="column about-us">
<div class="label">About Us</div>
<ul class="footer links">...</ul>
</div>
Any suggestions?
1 Answer 1
You need to use the argument directly without the array.
Instead of
<arguments>
<argument name="data" xsi:type="array">
<item name="text" xsi:type="string">About Us</item>
</argument>
</arguments>
You need:
<arguments>
<argument translate="true" name="text" xsi:type="string">About Us</argument>
</arguments>
Alternative
You can also try with the <action> tag:
<action method="setText">
<argument translate="true" name="text" xsi:type="string">About Us</argument>
</action>
Adding a div directly
You can also add a div directly in the text with the following:
<argument translate="true" name="text" xsi:type="string"><![CDATA[<div class="label">About Us</div>]]></argument>
-
How would you add an argument inside an existing block e.g. product.info.review block can it be referenced and added with another argument of type string?Devtype– Devtype2016年10月20日 11:13:46 +00:00Commented Oct 20, 2016 at 11:13
-
@Devtype totally. You can use
<referenceBlock name="product.info.review">to do soRaphael at Digital Pianism– Raphael at Digital Pianism2016年10月20日 11:17:28 +00:00Commented Oct 20, 2016 at 11:17 -
@RaphaelatDigitalPianism referencing a block doesn't work for me, on the other hand referencing a container does work. Am I missing something!!Devtype– Devtype2016年10月20日 16:10:32 +00:00Commented Oct 20, 2016 at 16:10
-
@Devtype no that should work for both blocks and containers. Feel free to create a new question and describe your problem in details ;)Raphael at Digital Pianism– Raphael at Digital Pianism2016年10月20日 16:12:32 +00:00Commented Oct 20, 2016 at 16:12
-
@RaphaelatDigitalPianism magento.stackexchange.com/questions/141891/…Devtype– Devtype2016年10月20日 16:22:46 +00:00Commented Oct 20, 2016 at 16:22
Explore related questions
See similar questions with these tags.