Re: [Radiant] Snippets with Parameter(s)
On Wed, Oct 1, 2008 at 7:26 PM, Jordan Isip [EMAIL PROTECTED] wrote: Hi All, What is the best approach to generating the following HTML? div class='section' div class='section-header' #{ title } /div div class='section-content' r:yield/ /div /div I would like to call it with something like: r:snippet title=NewsNews/r:snippet. Basically just using the snippet tag but I would like to be able to pass the title as a param. This is a good question, but I don't have an answer for you. ___ Radiant mailing list Post: Radiant@radiantcms.org Search: http://radiantcms.org/mailing-list/search/ Site: http://lists.radiantcms.org/mailman/listinfo/radiant
Re: [Radiant] Snippets with Parameter(s)
On Thu, Oct 2, 2008 at 9:46 AM, Joe Van Dyk [EMAIL PROTECTED] wrote: On Wed, Oct 1, 2008 at 7:26 PM, Jordan Isip [EMAIL PROTECTED] wrote: Hi All, What is the best approach to generating the following HTML? div class='section' div class='section-header' #{ title } /div div class='section-content' r:yield/ /div /div I would like to call it with something like: r:snippet title=NewsNews/r:snippet. Basically just using the snippet tag but I would like to be able to pass the title as a param. This is a good question, but I don't have an answer for you. Nevermind, I do. From http://www.ruby-forum.com/topic/125007 Usage: To call the snippet: r:snippet name='test-snippet' title='Joe Rules' Content is in here /r:snippet The snippet: div h2 r:var name='title' / /h2 p Content: r:yield / /p /div The code: # TODO Put into extension desc %{ crazy hack for getting params in snippets } tag snippet:var do |tag| var = tag.attr['name'] || nil if var.blank? %{bNO ATTR SPECIFIED/b} else ret_val = nil content = tag.context.instance_variable_get(:@tag_binding_stack).detect{ |slot| slot.name == snippet} if !content.blank? ret_val = content.attr[var] || nil if ret_val.blank? %{bCOULDN'T FIND ATTR #{var}/b} else %{#{ret_val}} end else %{bERROR IN GETTING CONTENT/b} end end end ___ Radiant mailing list Post: Radiant@radiantcms.org Search: http://radiantcms.org/mailing-list/search/ Site: http://lists.radiantcms.org/mailman/listinfo/radiant
Re: [Radiant] Snippets with Parameter(s)
Thank you! This is exactly what I needed. Works perfectly. - Original Message From: Joe Van Dyk [EMAIL PROTECTED] To: radiant@radiantcms.org Sent: Thursday, October 2, 2008 10:06:21 AM Subject: Re: [Radiant] Snippets with Parameter(s) On Thu, Oct 2, 2008 at 9:46 AM, Joe Van Dyk [EMAIL PROTECTED] wrote: On Wed, Oct 1, 2008 at 7:26 PM, Jordan Isip [EMAIL PROTECTED] wrote: Hi All, What is the best approach to generating the following HTML? div class='section' div class='section-header' #{ title } /div div class='section-content' r:yield/ /div /div I would like to call it with something like: r:snippet title=NewsNews/r:snippet. Basically just using the snippet tag but I would like to be able to pass the title as a param. This is a good question, but I don't have an answer for you. Nevermind, I do. From http://www.ruby-forum.com/topic/125007 Usage: To call the snippet: r:snippet name='test-snippet' title='Joe Rules' Content is in here /r:snippet The snippet: div h2 r:var name='title' / /h2 p Content: r:yield / /p /div The code: # TODO Put into extension desc %{ crazy hack for getting params in snippets } tag snippet:var do |tag| var = tag.attr['name'] || nil if var.blank? %{bNO ATTR SPECIFIED/b} else ret_val = nil content = tag.context.instance_variable_get(:@tag_binding_stack).detect{ |slot| slot.name == snippet} if !content.blank? ret_val = content.attr[var] || nil if ret_val.blank? %{bCOULDN'T FIND ATTR #{var}/b} else %{#{ret_val}} end else %{bERROR IN GETTING CONTENT/b} end end end ___ Radiant mailing list Post: Radiant@radiantcms.org Search: http://radiantcms.org/mailing-list/search/ Site: http://lists.radiantcms.org/mailman/listinfo/radiant ___ Radiant mailing list Post: Radiant@radiantcms.org Search: http://radiantcms.org/mailing-list/search/ Site: http://lists.radiantcms.org/mailman/listinfo/radiant
Re: [Radiant] Snippets with Parameter(s)
You are welcome, good sir. Joe On Thu, Oct 2, 2008 at 10:30 AM, Jordan Isip [EMAIL PROTECTED] wrote: Thank you! This is exactly what I needed. Works perfectly. - Original Message From: Joe Van Dyk [EMAIL PROTECTED] To: radiant@radiantcms.org Sent: Thursday, October 2, 2008 10:06:21 AM Subject: Re: [Radiant] Snippets with Parameter(s) On Thu, Oct 2, 2008 at 9:46 AM, Joe Van Dyk [EMAIL PROTECTED] wrote: On Wed, Oct 1, 2008 at 7:26 PM, Jordan Isip [EMAIL PROTECTED] wrote: Hi All, What is the best approach to generating the following HTML? div class='section' div class='section-header' #{ title } /div div class='section-content' r:yield/ /div /div I would like to call it with something like: r:snippet title=NewsNews/r:snippet. Basically just using the snippet tag but I would like to be able to pass the title as a param. This is a good question, but I don't have an answer for you. Nevermind, I do. From http://www.ruby-forum.com/topic/125007 Usage: To call the snippet: r:snippet name='test-snippet' title='Joe Rules' Content is in here /r:snippet The snippet: div h2 r:var name='title' / /h2 p Content: r:yield / /p /div The code: # TODO Put into extension desc %{ crazy hack for getting params in snippets } tag snippet:var do |tag| var = tag.attr['name'] || nil if var.blank? %{bNO ATTR SPECIFIED/b} else ret_val = nil content = tag.context.instance_variable_get(:@tag_binding_stack).detect{ |slot| slot.name == snippet} if !content.blank? ret_val = content.attr[var] || nil if ret_val.blank? %{bCOULDN'T FIND ATTR #{var}/b} else %{#{ret_val}} end else %{bERROR IN GETTING CONTENT/b} end end end ___ Radiant mailing list Post: Radiant@radiantcms.org Search: http://radiantcms.org/mailing-list/search/ Site: http://lists.radiantcms.org/mailman/listinfo/radiant ___ Radiant mailing list Post: Radiant@radiantcms.org Search: http://radiantcms.org/mailing-list/search/ Site: http://lists.radiantcms.org/mailman/listinfo/radiant ___ Radiant mailing list Post: Radiant@radiantcms.org Search: http://radiantcms.org/mailing-list/search/ Site: http://lists.radiantcms.org/mailman/listinfo/radiant