Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with passing inline params and losing outer context #129

Closed
vybs opened this issue Aug 30, 2012 · 3 comments
Closed

Issue with passing inline params and losing outer context #129

vybs opened this issue Aug 30, 2012 · 3 comments
Assignees
Milestone

Comments

@vybs
Copy link
Contributor

vybs commented Aug 30, 2012

Initially reported as a select helper issue, but turns out not. Read below

@ghost ghost assigned vybs Aug 30, 2012
@smfoote
Copy link
Contributor

smfoote commented Aug 31, 2012

I have observed the same issue. Here is an example of JSON, Dust, and output:

//JSON
{
  "id": 2345
  "actions": {
    primaryAction: "connect",
    secondaryActions: [
      "view",
      "message",
      "share"
    ]
  }
}
{! Dust template 1 !}
<div id="actions">
  {#actions}
    <div class="drop-button">
    {?primaryAction}
      {>switchTemplate level="pri" actionType="{primaryAction}"/}
    {/primaryAction}
    {?secondaryActions}
      <ul class="secondary-actions menu">
        {#secondaryActions}
          <li>
            {>switchTemplate level="sec" actionType="{.}"/}
          </li>
        {/secondaryActions}
      </ul>
    {/secondaryActions}
  </div>
  {/actions}
</div>
{! switchTemplate.tl !}
{@select key="{actionType}"}
  {@eq value="view"}
    <a class="{level}" href="view/{id}">{actionType}</a>
  {/eq}
  {@eq value="connect"}
    <a class="{level}" href="connect/{id}">{actionType}</a>
  {/eq}
  {@eq value="message"}
    <a class="{level}" href="message/{id}">{actionType}</a>
  {/eq}
  {@eq value="share"}
    <a class="{level}" href="share/{id}">{actionType}</a>
  {/eq}
{/select}
<!-- Dust output -->
<div id="actions">
    <div class="drop-button">
      <a class="pri" href="connect/2345">Connect</a>
      <ul class="secondary-actions menu">
          <li>
            <a class="sec" href="view/"></a>
          </li>
          <li>
            <a class="sec" href="message/"></a>
          </li>
          <li>
            <a class="sec" href="share/"></a>
          </li>
      </ul>
  </div>
</div>

I have greatly simplified the actual use case for demonstration (so much that a switch is not even necessary in my example). What is important to note in the output is that {actionType} and {id} are not available, but only for the secondary actions (when looping through the array).

@vybs
Copy link
Contributor Author

vybs commented Sep 4, 2012

Now tracked in the dust-helpers repo. my bad I added the ticket here

@vybs vybs closed this as completed Sep 4, 2012
@vybs
Copy link
Contributor Author

vybs commented Sep 4, 2012

@smfoote

this has nothing to do with select helper.

The issue is with the partials taking params ( remove those params and the {id} is printed inside the template , even with select)

Interesting case, not sure how we did not catch this with @jimmyhchan change

if (params){ //put the params context second to match what section does. {.} matches the current context without parameters //remove head context = context.rebase(ctx.tail); //put params on context = context.push(params); //reattach the head context = context.push(tempHead); }

  {#actions}
   <div class="drop-button">
    {?primaryAction}
     {>"switchTemplate "/}
    {/primaryAction}
   {?secondaryActions}
     <ul class="secondary-actions menu">
    {#secondaryActions}
      <li>
        {>"switchTemplate "/}
      </li>
    {/secondaryActions}
    </ul>
   {/secondaryActions}
 </div>
 {/actions}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants