Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

oli studholme

Linking to articles using the article’s weblog in ExpressionEngine

I have an index template that displays articles from several sections (weblogs), but when linking to an article we must specify the template_group and template to use. I have different template groups for each section, and want to use them as they define the article’s URL. However, the obvious way of using {title_permalink="{weblog_short_name}/index"} doesn’t work (although we can use {segment_#} like this).

You can do this by passing the {weblog_short_name} and {entry_id} of each article to an embedded template using embedded variables:

<!-- the index template that calls the embedded template -->
{exp:weblog:entries weblog="not pages" orderby="date" sort="desc" limit="10" disable="categories|comments|member_data|pagination|trackbacks"}
<div class="article">
{date_heading}<h3 class="date">{entry_date}</h3>{/date_heading}
<h3>{weblog}</h3>
<h2 class="title"><a href="{target_url}" title="{target_title}">{title}</a></h2>
{summary}
<!-- the next line embeds the template and sets the variables -->
<p><a href="{embed="snippet/body-hp-link" the_weblog="{weblog_short_name}" the_entry_id="{entry_id}"}">Read more</a> or comment&hellip;</p>
</div>{/exp:weblog:entries}


<!-- the embedded template -->
{exp:weblog:entries weblog="{embed:the_weblog}" entry_id="{embed:the_entry_id}" dynamic="off" disable="categories|comments|member_data|pagination|trackbacks"}{title_permalink="{embed:the_weblog}/index"}{/exp:weblog:entries}

trying to add trim_mode to BackDoor extension for RadiantCMS

// here's what I'm doing atm

<r:erb_tag name="langLink" >
<r:erb><%# url = <%= <r:expand tag="url" /> %><%= if (/\/en/.match(url))
url.sub(/\/([^\/]+)/,"/ja")
else
url.sub(/\/([^\/]+)/,"/en")
end %></r:erb></r:erb_tag>
<ul class="lang-links">
<li><r:if_url matches="^\/ja"><em>日本語</em></r:if_url><r:unless_url matches="^\/ja"><a href="<r:langLink></r:langLink>" title="<r:title /> in Japanese">日本語</a></r:unless_url></li>
<li><r:if_url matches="^\/en"><em>English</em></r:if_url><r:unless_url matches="^\/en"><a href="<r:langLink></r:langLink>" title="<r:title /> の英文ページ" class="last">Engish</a></r:unless_url></li>
</ul>


// but this gives me urls like this (note line break from if/else)

<li><a href="
/ja/" title="This page in Japanese">日本語</a></li>


// so let's hack BackDoor's erg tag

  tag "erb" do |tag|
    ERB.new( tag.expand).result( binding)
  end


// here's the documentation from erb.new

If trim_mode is passed a String containing one or more of the following modifiers, ERB will adjust its code generation as listed:

    %  enables Ruby code processing for lines beginning with %
    <> omit newline for lines starting with <% and ending in %>
    >  omit newline for lines ending in %>


// here's your new erb tag

  tag "er" do |tag|
    ERB.new(tag.expand, nil, true).result(binding)
  end


// but I'm not sure how to call it

<r:er trim_mode=">"> <!-- looks wack and doesn't work -->