# Tags using a snippet as a block parameter?

**URL:** <https://www.ruby-forum.com/t/tags-using-a-snippet-as-a-block-parameter/98894>\
**Category:** Radiant CMS\
**Created:** [July 18, 2006, 9:46pm UTC](https://www.ruby-forum.com/t/tags-using-a-snippet-as-a-block-parameter/98894 "2006-07-18T21:46:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jay-levitt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@jay-levitt](https://www.ruby-forum.com/u/jay-levitt)\
**Post date:** [July 18, 2006, 9:46pm UTC](https://www.ruby-forum.com/t/tags-using-a-snippet-as-a-block-parameter/98894/1 "2006-07-18T21:46:10Z")

</div>

I’m creating an image-tab navigation plugin. Right now, I’m just  
automatically scraping the top level of page titles and URLs. But it  
would be nicer to provide a syntax like

\<r:navtab page\_snippet=“nav-pages”/\>

(Aside: am I the only one that would prefer hyphens to underscores here?  
But Radius doesn’t allow hyphens in attribute names for some reason.  
Anyway.)

Snippet nav-pages:

\<r:find url="/"\>  
\<r:children:each by=“breadcrumb”\>  
\<r:unless\_url matches="/sitemap"\>  
\<r:link/\>  
\</r:unless\_url\>  
\</r:children:each\>  
\</r:find\>

This works, if I snag @parser from Behavior:

if (tag.attr[‘page\_snippet’])  
p @parser.parse(%Q|\<r:snippet  
name="#{tag.attr[‘page\_snippet’]}"/\>|)  
…

Is that the right way to do it? Am I headed for trouble?

Jay L.

---

<div class="post-metadata">

**Author:** ![jay-levitt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@jay-levitt](https://www.ruby-forum.com/u/jay-levitt)\
**Post date:** [July 18, 2006, 10:06pm UTC](https://www.ruby-forum.com/t/tags-using-a-snippet-as-a-block-parameter/98894/2 "2006-07-18T22:06:24Z")

</div>

In regards to hyphens versus underscores, I prefer hyphens too.

---

<div class="post-metadata">

**Author:** ![jay-levitt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@jay-levitt](https://www.ruby-forum.com/u/jay-levitt)\
**Post date:** [July 19, 2006, 5:11am UTC](https://www.ruby-forum.com/t/tags-using-a-snippet-as-a-block-parameter/98894/3 "2006-07-19T05:11:33Z")

</div>

Kyle H. wrote:

> In regards to hyphens versus underscores, I prefer hyphens too.

I think I prefer underscores. Radius is loosely based on Ruby so it uses  
underscores. If I wrote it in scheme I might prefer hyphens. 🙂

Actually, it’s probably better if we stick with underscores and stay  
consistent with what we are have already done. Though hyphens are  
admittedly more visually pleasing, underscores to have the effect of  
encouraging you to find precise words for attribute names. I don’t think  
it’s an accident that none of the normal HTML attributes are two words.

Mmmm… does XML make allowances for two word attribute names? What  
character do they use?

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)

---

<div class="post-metadata">

**Author:** ![jay-levitt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@jay-levitt](https://www.ruby-forum.com/u/jay-levitt)\
**Post date:** [July 19, 2006, 11:07am UTC](https://www.ruby-forum.com/t/tags-using-a-snippet-as-a-block-parameter/98894/4 "2006-07-19T11:07:40Z")

</div>

Jay L. wrote:

> … For some reason, I never want to use hyphens in  
> code, but I always do in declarative tag-based languages.

A hyphen in code can easily be confused with a subtraction operation.  
Most programming languages therefore don’t allow hyphens in identifiers.

Regards,  
Erik.

–  
Erik van Oosten

> **[Day to day stuff](http://day-to-day-stuff.blogspot.com/)**
>
> Experiences from a hard core JVM programmer. Likes to keep things simple.

---

<div class="post-metadata">

**Author:** ![jay-levitt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@jay-levitt](https://www.ruby-forum.com/u/jay-levitt)\
**Post date:** [July 19, 2006, 1:01pm UTC](https://www.ruby-forum.com/t/tags-using-a-snippet-as-a-block-parameter/98894/5 "2006-07-19T13:01:31Z")

</div>

So, back to the original question:

---

<div class="post-metadata">

**Author:** ![jay-levitt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@jay-levitt](https://www.ruby-forum.com/u/jay-levitt)\
**Post date:** [July 19, 2006, 3:59pm UTC](https://www.ruby-forum.com/t/tags-using-a-snippet-as-a-block-parameter/98894/6 "2006-07-19T15:59:22Z")

</div>

Jay L. wrote:

> So, back to the original question:
> 
> > This works, if I snag @parser from Behavior:
> > 
> > if (tag.attr[‘page\_snippet’])  
> > p @parser.parse(%Q|\<r:snippet name=“#{tag.attr[‘page\_snippet’]}”/\>|)  
> > …
> > 
> > Is that the right way to do it? Am I headed for trouble?

Use this instead:

tag.render(‘snippet’, ‘name’ =\> tag.attr[‘page\_snippet’])

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)

---

<div class="post-metadata">

**Author:** ![jay-levitt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@jay-levitt](https://www.ruby-forum.com/u/jay-levitt)\
**Post date:** [July 19, 2006, 11:04am UTC](https://www.ruby-forum.com/t/tags-using-a-snippet-as-a-block-parameter/98894/7 "2006-07-19T11:04:27Z")

</div>

John W. Long wrote:

> it’s an accident that none of the normal HTML attributes are two words.
> 
> Mmmm… does XML make allowances for two word attribute names? What  
> character do they use?

Actually, XML allows both hyphens and underscores in both names and  
elements.

The only XML I’ve really used, XSLT, uses hyphens. (A quick survey  
shows RSS, Atom and XAML using camelCase, and XUL using  
runtogetherwords, and XQuery using hyphens. )

CSS (which isn’t XML, of course, but which we’re often editing at the  
same time as Radius templates) uses hyphens as well, which is what  
triggered my thought. For some reason, I never want to use hyphens in  
code, but I always do in declarative tag-based languages.

Jay

---

<div class="post-metadata">

**Author:** ![jay-levitt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@jay-levitt](https://www.ruby-forum.com/u/jay-levitt)\
**Post date:** [July 22, 2006, 4:42am UTC](https://www.ruby-forum.com/t/tags-using-a-snippet-as-a-block-parameter/98894/8 "2006-07-22T04:42:33Z")

</div>

Jay L. wrote:

> Is there any way around that, to bump the “program counter”?

I’m not quite sure what you mean. If you mean: “Is there a way to render  
child tags for their side effects rather than the content they produce?”  
Then the answer is yes. Whether or not the tag renders it’s contents is  
totally up to the tag. Have a look at the \<r:navigation /\> tag in  
page\_context.rb to see how it’s done.

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)

---

<div class="post-metadata">

**Author:** ![jay-levitt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@jay-levitt](https://www.ruby-forum.com/u/jay-levitt)\
**Post date:** [July 22, 2006, 12:35am UTC](https://www.ruby-forum.com/t/tags-using-a-snippet-as-a-block-parameter/98894/9 "2006-07-22T00:35:05Z")

</div>

John W. Long wrote:

> Use this instead:
> 
> tag.render(‘snippet’, ‘name’ =\> tag.attr[‘page\_snippet’])

Thanks - that works great. I could swear I tried that first… ah well.

So I’m thinking that, rather than have to create a separate snippet,  
what I’d really like to do is:

\<r:navtabs\>  
  
\</r:navtabs\>

I imagine I can figure out the contents of the container tag and parse  
them, but I can’t think of a way to then skip over those contents when  
rendering the actual page - they’ll get parsed by the real parser.

Is there any way around that, to bump the “program counter”?

Jay L.
