Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

Why does <% with Content %>$LimitWordCountXML(10)<% end_with %> but $Content.LimitWordCountXML(10) doesn't


3 Posts   560 Views


Community Member, 160 Posts

3 April 2013 at 11:51am

Edited: 03/04/2013 12:03pm


I'm trying to create a number limited list of 'latest blog posts' in my side bar, that appears in all pages (Blog and non-blog) of a site. The listing is to have the blog title, a number limited synopsis of the content and a link.

However, it appears that I can't call $Content.LimitWordCountXML(10) directly... Instead, I have use use <% with Content %>$LimitWordCountXML(10)<% end_with %>.

Here is my code.

In Page_Controller - Page.php:

   function LatestPosts($postLimit=3) {
    $latestPosts = null;
    $blogHolderAvailable = BlogHolder::get();
    if ($blogHolderAvailable) {
       $latestPosts = BlogEntry::get()->sort("Date", "ASC")->limit($postLimit);
    return $latestPosts;

Template Snippet - doesn't work

      <% loop $LatestPosts %>
         <li class="latestPostSynopsis">
            <a href="$Link" title="<% _t('VIEWFULL', 'View full post titled -') %> '$Title'">Read More</a>
      <% end_loop %>

The above template outputs:

      <p>This is the full blog content that has been output instead of being word limited to 10.LimitWordCountXML(10)...<p>
      <a href="/blog1" title="Full blog1 title">Read More</a>

When I replace $Content.LimitWordCountXML(10) with <% with Content %>$LimitWordCountXML(10)<% end_with %>, it works correctly.

Is it not possible to pass in parameters to a sub-property the way I have done it? Do I need to enter into the scope of the property ($Content) using <% with %>to call methods and pass parameters?

Thank you.


Community Member, 175 Posts

3 April 2013 at 9:58pm

In your template, try:


I wonder if it's picking up those extra dots after and that's what's throwing it.


Community Member, 160 Posts

4 April 2013 at 11:51am

You're right! Great suggestion! Surrounding the statement in curly braces got it working.

Thanks Kinglozzer.