Any reason this shouldn’t be part of page_context? It’s incredibly
handy for nav.
define_tag 'parent' do |tag|
tag.locals.page = page.parent
tag.expand
end
Any reason this shouldn’t be part of page_context? It’s incredibly
handy for nav.
define_tag 'parent' do |tag|
tag.locals.page = page.parent
tag.expand
end
You should keep the current page so you can come back to it afterwards,
to
allow showing more data from the starting page.
Jay L. wrote:
Any reason this shouldn’t be part of page_context? It’s incredibly
handy for nav.define_tag 'parent' do |tag| tag.locals.page = page.parent tag.expand end
This is a great idea. Please submit a patch.
–
John L.
http://wiseheartdesign.com
Andrew H. wrote:
It needs this tweak:
define_tag ‘parent’ do |tag|
tag.locals.page = page.parent || page
tag.expand
endNote the “|| page” on the second line.
Instead of taking the approach above, let’s do this:
define_tag ‘parent’ do |tag|
parent = tag.locals.page.parent
tag.locals.page = parent
tag.expand unless parent.nil?
end
This way the tag will not be rendered if the parent doesn’t exist. The
above also makes the tag context sensitive (so you can use it inside a
children:each tag).
We should also add the if_parent and unless_parent tags:
define_tag ‘if_parent’ do |tag|
tag.expand unless tag.locals.page.parent.nil?
end
define_tag ‘unless_parent’ do |tag|
tag.expand if tag.locals.parent.nil?
end
If someone can get me a unit tested patch for this I’ll apply it.
–
John L.
http://wiseheartdesign.com
John W. Long wrote:
This is a great idea. Please submit a patch.
Agreed. I can now do the following to have a heading that is itself a
link to the parent page, in the manner of many Wiki engines:
However, this breaks horribly on the root page and in so doing reveals a
small bug in the parent tag code. It needs this tweak:
define_tag ‘parent’ do |tag|
tag.locals.page = page.parent || page
tag.expand
end
Note the “|| page” on the second line.
Things get a bit hideous if we want to avoid having a link on the Home
page in the heading, though, assuming you’re using the construct above
in a layout. Indenting things a bit to make it more legible, I’ve got
this right now:
<r:unless_url matches="^/$">
<r:parent><r:link>
<r:page><r:title /></r:page>
</r:link></r:parent>
</r:unless_url>
<r:if_url matches="^/$">
<r:title />
</r:if_url>
Is there a more elegant approach?
Jay L. wrote:
I’m in the process of moving but will submit something this week with
tests unless beats me to it…Jay
Has this been submitted? I couldn’t find it after a cursory search.
John W. Long wrote:
Instead of taking the approach above, let’s do this:
define_tag ‘parent’ do |tag|
parent = tag.locals.page.parent
tag.locals.page = parent
tag.expand unless parent.nil?
end
I like that much better - a parent tag should never return self! This
makes it consistent with child behavior.
I’m in the process of moving but will submit something this week with
tests unless beats me to it…
Jay
Dave C. wrote:
There’s something about parents tags at
http://dev.radiantcms.org/radiant/wiki/HowToDefineGlobalTags
Yes, I submitted that addition to the page. I use those tag definitions
right now on seancribbs.com.
Sean
On 14/09/06, Joseph B. [email protected] wrote:
Jay L. wrote:
I’m in the process of moving but will submit something this week with
tests unless beats me to it…Jay
Has this been submitted? I couldn’t find it after a cursory search.
There’s something about parents tags at
http://dev.radiantcms.org/radiant/wiki/HowToDefineGlobalTags
–
Regards,
Dave
Actually, the parent tag is in trunk as of [162]. Here’s the patch if
you’re interested:
http://dev.radiantcms.org/radiant/attachment/ticket/451/parent_tag.diff
Jesse
Jesse Newland wrote:
Actually, the parent tag is in trunk as of [162]. Here’s the patch if
you’re interested:http://dev.radiantcms.org/radiant/attachment/ticket/451/parent_tag.diff
Jesse
argh. Guess I didn’t restart radiant after updating and assumed it
wasn’t applied yet.
Dave C. wrote:
On 14/09/06, Joseph B. [email protected] wrote:
Jay L. wrote:
I’m in the process of moving but will submit something this week with
tests unless beats me to it…Jay
Has this been submitted? I couldn’t find it after a cursory search.
There’s something about parents tags at
http://dev.radiantcms.org/radiant/wiki/HowToDefineGlobalTags
–
Regards,
Dave
That probably shouldn’t be on that page because there is no parent tag
unless you create one yourself.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs