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

Ignore mustache interpolation in brick source file/files #1137

Open
2 tasks
PrimeTimeTran opened this issue Nov 4, 2023 · 2 comments
Open
2 tasks

Ignore mustache interpolation in brick source file/files #1137

PrimeTimeTran opened this issue Nov 4, 2023 · 2 comments
Assignees
Labels
question Further information is requested waiting for response Waiting for additional information

Comments

@PrimeTimeTran
Copy link

PrimeTimeTran commented Nov 4, 2023

Description

Add the ability to ignore mustache {{}} interpolation. There may be cases in which a brick uses a framework which itself has mustache syntax and we want to preserve the {{}} that's inside of the brick.

Requirements

  • Ability to label a file or {{}} as ignored/preserved ignore mustache.
  • Generated brick that doesn't parse/interpolate the labeled/preserved {{}} with cli vars

Additional Context

I have a brick file which contains a vue component.

<template>
  <div class="flex justify-center bg-red-100">
    <div class="mr-16 text-center">
      <h1>Undone</h1>
      <div>
        {{ countDone }}
      </div>
    </div>
    <div class="mr-16 text-center">
      <h1>Done</h1>
      <div>
        {{ countUndone }}
      </div>
    </div>
  </div>
</template>

<script setup>
const { countDone, countUndone } = useTodos()
</script>

Vue uses mustache syntax to inject variables into it's components/templates. When I generate my brick I end up with this.

<template>
  <div class="flex justify-center bg-red-100">
    <div class="mr-16 text-center">
      <h1>Undone</h1>
      <div>

      </div>
    </div>
    <div class="mr-16 text-center">
      <h1>Done</h1>
      <div>
      
      </div>
    </div>
  </div>
</template>

<script setup>
const { countDone, countUndone } = useTodos()
</script>

Not sure best way to do this. Could one of the following work?

  • {{! }}
  • {{@ }}
  • {{- }}

I tried {{{}}} but it didn't work. Thanks so much for your suppport.

@PrimeTimeTran
Copy link
Author

I can preserve the mustaches using this syntax, {{& }}.

<template>
  <div class="flex justify-center bg-red-100">
    <div class="mr-16 text-center">
      <h1>Undone</h1>
      <div>{{& countUndone }}</div>
    </div>
    <div class="mr-16 text-center">
      <h1>Done</h1>
      <div>{{& countDone }}</div>
    </div>
  </div>
</template>

<script setup>
const { countDone, countUndone } = useTodos()
</script>

But the variables have to be defined inside of brick.yaml.

vars:
  countDone:
    type: string
    default: '{{ countDone }}'
  countUndone:
    type: string
    default: '{{ countUndone }}'

Is there a way to define vars outside of brick.yaml? With this work around the user is prompted even though they shouldn't be, these variables aren't specific to the project/user.

Thanks for your help. I poked around documentation and didn't see it.

@felangel
Copy link
Owner

felangel commented Nov 8, 2023

@PrimeTimeTran you can use the mustacheCase lambda to preserve {{ }} brackets in your rendered template. Hope that helps 👍

@felangel felangel added question Further information is requested waiting for response Waiting for additional information labels Nov 8, 2023
@felangel felangel self-assigned this Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested waiting for response Waiting for additional information
Projects
None yet
Development

No branches or pull requests

2 participants