0

I found a lot of similar titles but none of them help me out of my issue.

I'm about to insert a block into the footer section on all pages so I added below code at the end of:

app/design/frontend/company/theme/layout/local.xml

just before the </layout> tag.

<!-- Instagram Scroller --> <default> <!-- to display on all pages --> <!-- if name="head" exists then put in the existing tag --> <reference name="head"> <action method="addItem"><type>skin_js</type><name>js/instashow/jquery.instashow.packaged.js</name></action> </reference> <reference name="footer"> <block type="core/template" name="instascroller_script" template="instascroller/script.phtml"/> </reference> </default> 

And I put my content in

app/design/frontend/company/theme/template/instascroller/script.phtml

Then I put below code in

app/design/frontend/company/theme/template/page/html/footer.phtml

<div class="instascroller"> <?php echo $this->getBlockHtml('instascroller_script'); ?> </div> 

Then Flush the cache

---- SOLVED ----

Thanks to everyone who viewed, commented, answered this question.

First of all, I should place the <reference name="footer"> in the <default> tag. This solved my issue of not appearing on all pages.

Secondly, I should put <action method="addItem"> in the existing <reference name="head"> tag but I mistakenly created another one.

At last, I forgot to flush the cache.

I updated my question and wish this can help others.

Again thanks to everyone.

4
  • Your script.phtm file content will be show only in instagram/scroller/index action once you run. Commented Jun 22, 2017 at 7:32
  • You want to display it on all pages or only your custom page? Commented Jun 22, 2017 at 7:33
  • @s-h-patel, on all pages. Commented Jun 22, 2017 at 23:28
  • I changed <instagram_scroller> to <default> and confirmed instascroller/script.phtml is placed under template/ and js/instashow/jquery.instashow.packaged.js is under skin/frontend/company/theme/ but var_dump( $this->getBlockHtml('instascroller_script') ) still returns string(0) "". Commented Jun 22, 2017 at 23:47

2 Answers 2

4

The handle you are using belongs to a specific page, so your content will be showing on instagram/scroller page only. Please check it on the page.

For displaying it on all pages, Please call it using the following code.

<default> <reference name="head"> <action method="addItem"><type>skin_js</type><name>js/instashow/jquery.instashow.packaged.js</name></action> </reference> <reference name="footer"> <block type="core/template" name="instascroller_script" template="instascroller/script.phtml"/> </reference> </default> 

You have placed the template file at wrong path.Please put the template file at the following path:

app/design/frontend/company/theme/template/instascroller/script.phtml 

Clear the cache for the changes to be displayed.

1
  • It doesn't work. Could it be anything I'm missing? Commented Jun 22, 2017 at 23:37
1

1) Your are missing in your layout handle

<instagram_scroller> //here the layout handle is not correct, it should be like something like <instagram_scroller_index> <reference name="head"> <action method="addItem"><type>skin_js</type><name>js/instashow/jquery.instashow.packaged.js</name></action> </reference> <reference name="footer"> <block type="core/template" name="instascroller_script" template="instascroller/script.phtml"/> </reference> </instagram_scroller> 

2) The layout handle is constructed like this: <routerName_controllerName_actionName>

3) You are also missing in template path, you put it in: app/design/frontend/company/theme/template/instascroller/script.phtml instead app/design/frontend/company/theme/instascroller/script.phtml

4) You put a JS file in : skin/frontend/company/theme/js/instashow/jquery.instashow.packaged.js

5) And use <?php echo $this->getBlockHtml('instascroller_script'); ?>

3
  • Thanks for answering my question. I changed <instagram_scroller> to <default> as I want my code appear on all pages. instascroller/script.phtml is for sure under app/design/frontend/company/theme/template/. JS files are at appropriate position. But I still get nothing with <?php var_dump( $this->getBlockHtml('instascroller_script') ); ?> in the page/html/footer.phtml. I use var_dump because I want see at least the script has been run in footer.phtml. The result is string(0) "" which means getBlockHtml is called but can't find instascroller_script? Commented Jun 22, 2017 at 23:44
  • For All pages yes you have to put <default> instead, you did not specify it in the question. For getBlockHtml () its not possible it should work, maybe you are missing in a block type ! Commented Jun 23, 2017 at 0:09
  • Yes I forgot to mention it in the first place. It works then after I flushed the cache. I need to be more careful and pay more attention to details. Commented Jun 23, 2017 at 1:13

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.