Foreach to get pages within a child pages container

135 views
Skip to first unread message

Tony Gayter

unread,
May 1, 2013, 12:16:19 PM5/1/13
to reddot-c...@googlegroups.com
I have a page(a) which has children(x), these children have a container which contains instances of other templates(y). I need to get the value from one of these (y) onto the top page(a)

I am currently just trying to list the children (y) onto the top page, then I can work out how to get the values but I'm getting no output. I don't often use foreach so Im getting a little stuck. Any pointers?

<reddot:cms>
   <foreach itemname="item" object="Context:CurrentIndex.SubIndexes" countername="counter">
      <htmltext>
         <div class="list-item">
            <img src="http://placehold.it/180x119">
            <h2><a href="<%!! Store:item.GetUrl() !!%>"><%!! Store:item.Headline !!%></a></h2>
      </htmltext>

               <foreach itemname="iteminner" object="Store:item.Elements"> 
                  <output type="object" object="Store:iteminner.Name"/> 
               </foreach> 

      <htmltext>
         <p> <a href="<%!! Store:item.GetUrl() !!%>">Read more ></a></p>
         </div>
      </htmltext>
   </foreach>
</reddot:cms>

Jian Huang

unread,
May 2, 2013, 9:31:28 AM5/2/13
to reddot-c...@googlegroups.com
Hi Tony,

OOOOHHHH, a deep pull through.  I guess you have a news listing page, which lists news articles, and each new article has the news content inside a page connected to its con_body.

What I usually do now a days is in published mode, use AJAX, from a page(a), to pull content from children(x).  There is no other template instances (y) because they become part of children (x) at publish time.  Anyways, that's just me.  Let me get back to your rendertag solution.

Solution:
<!IoRangeList>

<div class="list-item">
    <img src="http://placehold.it/180x119">
    <!-- Display Nested Text Field -->
    <%!! Context:Pages.GetPage(Guid:<%inf_page_guid%>).GetElementByName(con_body).Value[Int32:0].GetElementByName(txt_article_teaser).GetHtml() !!%>
    <p><a href="<%lst_news_articles%>">Read more ></a></p>
</div>
<!/IoRangeList>

Note that I am mixing in some standard blockmarks and placeholders.  This is important to have because straight rendertag solution would run into the rendertag cache issue.  Lets say you had 2 articles, you added a 3rd one to the list.  Rendertag was cached at 2 articles and would not display the 3rd ones until a cache refresh.  Having a list blockmark in there causes the page cache to refresh when the list changes, which also refreshes the rendertag cache.

This solution is not perfect because it still encounters the cache issue for txt_article_teaser...

What is the most tasting non alcoholic beverage in your part of the world?  Why?  This solution should worth more than $1.  :).  Enjoy.

Best

-Jian
Reply all
Reply to author
Forward
0 new messages