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


Reply


3 Posts   548 Views

Avatar
vwd

Community Member, 160 Posts

3 April 2013 at 11:51am

Edited: 03/04/2013 12:03pm

Hi,

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

      <ul>
      <% loop $LatestPosts %>
         <li class="latestPostSynopsis">
            <h4>$MenuTitle</h4>
            <p>$Content.LimitWordCountXML(10)...</p>            
            <a href="$Link" title="<% _t('VIEWFULL', 'View full post titled -') %> '$Title'">Read More</a>
         </li>
      <% end_loop %>
      </ul>   

The above template outputs:

   <li>
      <h4>MyMenu1</h4>
      <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>
   </li>

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.
VWD.

Avatar
kinglozzer

Community Member, 171 Posts

3 April 2013 at 9:58pm

In your template, try:

<p>{$Content.LimitWordCountXML(10)}...</p>

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

Avatar
vwd

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.