[Radiant] Custom Tags and Code reuse

Sean Cribbs seancribbs at gmail.com
Tue Jan 16 15:02:18 CST 2007


The first line does two things: Assigns a blank Hash to
tag.locals.navigation and also assigns 'tag.locals.navigation' to the local
variable 'hash'.

Since the next line is 'tag.expand', the block you pass would be executed at
this point.  The "trick" is that if you re-assign
tag.locals.navigationinside that block, whatever you assigned it would
fall out of scope after
the block ends.

So, to get your values to pass through, you should either merge the contents
of your navigation_dynamic local in to tag.locals.navigation like so:

tag.locals.navigation.merge! tag.locals.navigation_dynamic

or set each individual key:

tag.locals.navigation[:here] # = something
tag.locals.navigation[:normal] #= something

The 'r:navigation' tag also expects that the elements in that hash will be
tag-binding Procs (for lack of a better word).

I have a plan for the <r:navigation> tag that I haven't completed yet, but
it will allow you to have both external links and dynamically generated
menus, so you could have something like:

<r:navigation>
  <r:children:each>
    <r:item>
      <r:label><r:title /></r:label>
      <r:href><r:url /></r:href>
    </r:item>
  </r:children:each>
  <r:normal>...</r:normal>
  ...
</r:navigation>

I also plan to have it support the old style for backwards compatibility's
sake, or even a combination.

Cheers,

Sean Cribbs

On 1/16/07, Michael Jones <mjfreshnspamfree at gmail.com> wrote:
> > I believe you can just set tag.locals.whatever inside the do...end
block.
>
> I tried to set my locals to be the locals of the navigation tag like this:
>
>  tag 'navigation_dynamic' do |tag|
>    tag.render('navigation', {'urls' => 'Resources:
> /resources/;Search: /resources/resources-search/;'}) do
>        tag.locals.navigation = tag.locals.navigation_dynamic
>    end
>  end
>
> I got the error about including a 'normal tag', I tried a few
> different approaches such as:
> tag.locals.navigation = {:normal=>'yo'}
>
> The navigation tag in the standard_tags.rb is kinda trick, could you
> explain the first line some?
>
> hash = tag.locals.navigation = {}
> tag.expand
>    raise TagError.new("`navigation' tag must include a `normal' tag")
> unless hash.has_key? :normal
>
> Also, is there a good way to log debugging from the tags?
>
> Thanks-
> Michael
> _______________________________________________
> Radiant mailing list
> Post:   Radiant at lists.radiantcms.org
> Search: http://radiantcms.org/mailing-list/search/
> Site:   http://lists.radiantcms.org/mailman/listinfo/radiant
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.radiantcms.org/pipermail/radiant/attachments/20070116/a3f80689/attachment.html


More information about the Radiant mailing list