Note that there are some explanatory texts on larger screens.

plurals
  1. POcontent_for blank when logged in
    primarykey
    data
    text
    <p>I'm implementing (more or less) <a href="http://codex.wordpress.org/Shortcode_API" rel="nofollow">WordPress's concept of shortcodes</a> in my Rails app. The problem is that when I <code>:yield</code> anything in my layout defined via <code>content_for</code> in the view, it's just blank. So the additional javascript and title tags are not rendered.</p> <p>In other words, calling <code>content_for? :title</code> in the layout returns false.</p> <p>This only happens <del>in posts/index, and <strong>only when I'm logged in</strong></del> <strong>when the <code>filter_shortcodes</code> helper is run.</strong> Has anyone encountered something like this before?</p> <p>In views/posts/index.html.haml:</p> <pre><code>- content_for :script do = javascript_include_tag '/assets/autoload.js' - content_for :title do Blog ... = render template: 'article-content', </code></pre> <p>And in views/article-content.html.haml (<code>filter_shortcodes</code> is a helper function defined in the <code>Shortcode</code> module.):</p> <pre><code>:plain #{filter_shortcodes instance.content} </code></pre> <p>I remain convinced that the problem is in my shortcode module, so here it is, back by unpopular demand:</p> <pre><code>module Shortcode def filter_shortcodes content content.gsub /(?&lt;!\\)\[.+\]/ do |code| # A shortcode must: # - be on its own line # - be [contained within square brackets] # - be named using only lowercase letters # If it contains parameters, they must come in the form: # key="value" shortcode = /^\s*\[(?&lt;name&gt;[a-z]+) (?&lt;params&gt;.*)\s*\]\s*$/.match code params_list = shortcode[:params].gsub /&amp;quot;|"/, '"' param_regexp = /([a-z]+)="([^"]*)"/ shortcode_params = {} params_list.scan param_regexp do |param| shortcode_params[param[0].to_sym] = param[1] end render_to_string template: "shortcodes/#{shortcode[:name]}", :locals =&gt; shortcode_params, layout: false end end end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload