comfortable-mexican-sofa icon indicating copy to clipboard operation
comfortable-mexican-sofa copied to clipboard

Partial tags not rendering local variables

Open lhjd opened this issue 4 years ago • 1 comments

Note: For general questions and feature requests please leave a message on Gitter: https://gitter.im/comfy/comfortable-mexican-sofa

Expected behavior

Tell us what should happen

  • when we want to render a partial template using the cms partial tag, the local variables should be passed along to the partial template

Actual behavior

  • the partial template is rendered, but the local variables are not passed to the template

Steps to reproduce

  1. Add a cms partial tag to a cms layout: {{ cms:partial "path/to/partial", local_var: "value" }}
  2. This tag will be converted to <%= render partial: "path/to/partial", locals: {"local_var" => "value"} %>
  3. Inside the partial template, <%= local_var %> will not be rendered.
  4. Workaround: use <%= local_assigns["local_var"] %> to render.

I've forked the comfy-demo to illustrate the issue. Steps to reproduce:

  1. git clone https://github.com/lhjd/comfy-demo/
  2. cd comfy-demo
  3. bundle install
  4. yarn install
  5. rails db:create
  6. rails db:migrate
  7. rails db:seed - to create a demo site called mydemo
  8. rails 'comfy:cms_seeds:import[mydemo, mydemo]' - import from mydemo cms seeds folder to mydemo site
  9. rails server
  10. go to http://localhost:3000

Actual: image

Expected: image

Workaround:

  1. use <%= local_assigns["local_var"] %> instead of <%= local_var %> in the partial template

I've created a branch workaround to illustrate this. Steps to reproduce:

  1. git checkout workaround
  2. go to http://localhost:3000

System configuration

Rails version: rails (6.0.2)

CMS version: comfortable_mexican_sofa (2.0.18 e13ce5d)

Ruby version: ruby '2.6.5'

lhjd avatar Mar 04 '20 17:03 lhjd

I can confirm this is happening.

Fodoj avatar Jul 09 '22 17:07 Fodoj