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

Dynamically passing content key from model to template #36

Closed
mikesparr opened this issue Apr 8, 2014 · 5 comments
Closed

Dynamically passing content key from model to template #36

mikesparr opened this issue Apr 8, 2014 · 5 comments

Comments

@mikesparr
Copy link

I read in #21 that you cannot pass in content key dynamically to a template. I am curious whether my issue in #35 could be solved by having a list of keys in the model object and the template could evaluate those keys and inject the proper content from the current resource bundle.

Example Model:

...
        filters: [
            {name_key:'filter.id', hint_key:'filter.hint.id'},
            {name_key:'filter.name', hint_key:'filter.hint.name'},
            {name_key:'filter.title', hint_key:'filter.hint.title'},
            {name_key:'filter.email', hint_key:'filter.hint.email'},
            ...
        ],
...

Example property bundle:

filter.id=ID
filter.hint.id=E.g. '1234'
filter.name=Name
filter.hint.name=E.g. 'Mike' or 'Sally Jones'
filter.title=Title
filter.hint.title=E.g. 'Broker'
filter.email=Email
filter.hint.email=E.g. 'joe@someco.com' or 'someco.com'

On the template perhaps:

...

{#filters}
<a href='#' title='{@pre type="content" key="{hint_key}" /}'>{@pre type="content" key="{name_key}" /}</a>
{/filters}

...

I appreciate steer on how best to accomplish #35 and whether this might be possible but I'm missing something.

@mikesparr
Copy link
Author

@jeffharrell is there no way within Controller to access language bundle to match a key value for current locale to a dynamic object returned from DB?

screen shot 2014-04-08 at 9 06 58 am

Say I have a Lucene search that includes facets with stats I want to update in sparklines as pages load, and sparkline file is include. I need sparkline file to be able to iterate through list of objects in model with stat count, list of bars, and a label to dynamically build 2 - 5 of these sparklines. The counts are okay but the label needs to match a key in bundle for current locale. I cannot seem to find a way to get this to work without hard-coding templates and lose the ability to just include a dynamic sparkline file that accepts list and renders mini stats.

Example model

        stats: [
            {key:'mini_stats.available', style:'sparkline_bar_good', value:'35', bars:[2,4,9,7,12,10,12]},
            {key:'mini_stats.sold_this_month', style:'sparkline_bar_neutral', value:'12', bars:[2,4,9,7,12,10,12]}
        ], 

Problem is even if I include key values matching bundle properties, since bundles evaluated at build time I'm unable to dynamically build this row of sparklines with the label for each stat. I cannot seem to find a way to render this content dynamically on the page and match language bundle key.

Goal would be to have a dust template that iterates through {#stats}<sparkline code here>{/stats} and could either evaluate the key sent from Model, or perhaps on Controller it can match keys and load proper label (i.e. Available, Sold This Mo, etc.).

Idea would be that the model includes label Available, Sold This Mo coming from facet filter results corresponding to counts and histograms. These are part of stats model list. The template could then do a Map lookup in bundle to match key {@pre type="content" key="miniStats[{label}]" /}. Since @pre only works at build time, is there a way to access at runtime or custom helper that could accomplish this?

@mikesparr
Copy link
Author

@jeffharrell I built a helper to solve the issue short term and sharing on my personal page at: https://github.com/mikesparr/Kraken_Example_i18n_Helper

I'll keep my eyes open if you solve dynamically matching keys in Controller or have a better way to do this but hopefully this will help others in short term. Feel free to share, take, etc.

@aredridel
Copy link
Contributor

We're moving away from build-time localization of templates, so this will be moot in the new design.

@brakon
Copy link

brakon commented Apr 14, 2015

What will be the new design without build-time localization?

@aredridel
Copy link
Contributor

Templates will include @pre (deprecated), @message (backward-compatible) or @formatMessage (via formatjs.io project) helpers, and you can plug in a language bundle resolver that will supply bundles of strings. At the moment, that means loading a language-specific <script> tag with the actual strings, in addition to the javascript bundle of your app.

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

No branches or pull requests

3 participants