I've got lots of these similar blocks inside my templates.
The only real difference between each block is the sku (ex. hdrPhotos, panos, twilightPhotos, exteriors).
I would much rather write a single template that takes a sku argument and loop through an array of skus to create each block, but how would I insert a value into something that's already using spacebars {{ }} ?
{{> afFieldInput name="servicesSelected.hdrPhotos.selected" type="boolean-checkbox" noselect="true"}},
{{formatToCurrency currentPrice.hdrPhotos}} or
{{{services "hdrPhotos" "html"}}} ?
<div class="col-md-12">
{{> afFieldInput name="servicesSelected.hdrPhotos.selected" type="boolean-checkbox" noselect="true"}}
<div class="divider small-margins">
</div>
<div class="item-description">
<p><b>{{formatToCurrency currentPrice.hdrPhotos}}</b> - {{services "hdrPhotos" "description"}}</p>
<p>{{{services "hdrPhotos" "html"}}}</p>
</div>
</div>
<div class="col-md-12">
{{> afFieldInput name="servicesSelected.panos.selected" type="boolean-checkbox" noselect="true"}}
<div class="divider small-margins">
</div>
<div class="item-description">
<p><b>{{formatToCurrency currentPrice.panos}}</b> - {{services "panos" "description"}}</p>
<p>{{{services "panos" "html"}}}</p>
</div>
</div>
<div class="col-md-12">
{{> afFieldInput name="servicesSelected.twilightPhotos.selected" type="boolean-checkbox" noselect="true"}}
<div class="divider small-margins">
</div>
<div class="item-description">
<p><b>{{formatToCurrency currentPrice.twilightPhotos}}</b> - {{services "twilightPhotos" "description"}}</p>
<p>{{{services "twilightPhotos" "html"}}}</p>
</div>
</div>
<div class="col-md-12">
{{> afFieldInput name="servicesSelected.exteriors.selected" type="boolean-checkbox" noselect="true"}}
<div class="divider small-margins">
</div>
<div class="item-description">
<p><b>{{formatToCurrency currentPrice.exteriors}}</b> - {{services "exteriors" "description"}}</p>
<p>{{{services "exteriors" "html"}}}</p>
</div>
</div>
I wasn't able to get it to work with string concatenation:
itemBlock: function(sku){
var string = '' +
'<div class="col-md-12">' +
'{{> afFieldInput class="track-order-change label-to-bold-if-checked" name="servicesSelected.hdrPhotos.selected" type="boolean-checkbox" noselect="true"}}' +
'<div class="divider small-margins">' +
'</div>' +
'<div class="item-description">' +
'<p><b>{{formatToCurrency currentPrice.' + sku + '}}</b> - {{services "' + sku + '" "description"}}</p>' +
'<p>{{{services "' + sku + '" "html"}}}</p>' +
'</div>' +
'</div>';
return string;
}
In my html template:
{{{itemBlock hdrPhotos}}}
The HTML portion of it comes out fine, but everything inside {{ }} and {{{ }}} gets rendered on the page in the literal form (see screenshot)
You should try with nested sub-expressions in a dedicated template.
{{ > yourSkuTemplate "youSkuType"}}
<template name="yourSkuTemplate ">
<div class="col-md-12">
{{> afFieldInput name=(skuServicesSelected) type="boolean-checkbox" noselect="true"}}
<div class="divider small-margins">
</div>
<div class="item-description">
<p><b>{{formatToCurrency (skuCurrentPrice)}}</b> - {{services (skuName) (skuyDescription}}</p>
<p>{{{services (skuName) (whatever)}}}</p>
</div>
</div>
</template>
Where skuServicesSelected skuName and all the other in parenthesis are other helpers
Related
I use the Handlebars template engine:
`{{#each classes}}
<div class="col_4">
<h4>{{this.title}}</h4>
<p>{{this.description}}</p>
<a class="button" href="/classes/{{_id}}/details">View Class</a>
</div>
{{/each}}`
Why is it not possible to address title and description as individual fields of this?
If I use "this" like this:
{{#each classes}}
<div class="col_4">
<h4>{{this}}</h4>
<p>{{this}}</p>
<a class="button" href="/classes/{{_id}}/details">View Class</a>
</div>
{{/each}}
all fields are displayed merged.
The following code works with an earlier version:
{{#each classes }}
<div class="col_4">
<h4>{{title}}</h4>
<p>{{description}}</p>
<a class="button" href="/classes/{{_id}}/details">View Class</a>
</div>
{{/each}}
Im new to symfony3 and I need a bit of help,I have a timeline page that contains posts and every post has a comment field so in order to do that I've installed the FOSCommentBundle following all the steps in this documentation https://github.com/FriendsOfSymfony/FOSCommentBundle/blob/master/Resources/doc/index.md and then I integrated it with the FOSUserBundle, and I did the following changes in the async.html.twig file :
<div id="fos_comment_thread">#comments</div>
<script type="text/javascript">
// thread id
var fos_comment_thread_id = 'pub';
// api base url to use for initial requests
var fos_comment_thread_api_base_url = 'localhost/Outdoors5/web/app_dev.php/threads';
// Snippet for asynchronously loading the comments
(function() {
var fos_comment_script = document.createElement('script');
fos_comment_script.async = true;
fos_comment_script.src = '{{ asset('bundles/foscomment/js/comments.js') }}';
fos_comment_script.type = 'text/javascript';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(fos_comment_script);
})();
</script>
but in the end I got very confused on how I use this ,I passed hours trying to understand and searching for tuto, but no luck.
this is my view
<section id="timeline">
{% for publication in publications %}
<div id="result"></div>
<div class="page-content page-app page-profil " >
<div class="profil-content">
<div class="row">
<div class="row">
<div class="item item-comment">
<div class="user">
<h5 class="name">{{ publication.idProfil.nom }}</h5>
<div class="clearfix">
<p class="time">{% if publication.dateCreation %}{{ publication.dateCreation|date('Y-m-d') }}{% endif %}</p>
</div>
<div class="comment">
<p class="c-primary m-b-0"><strong>{{ publication.texte }}</strong></p>
</div>
</div>
<div class="more">
<div class="row">
<div class="col-sm-4 like">
<i class="fa fa-heart"></i> Like
</div>
<div class="col-sm-4 more-comments">
<div class="comment-number">
<i class="icon-bubble"></i> Comments<span class="pull-right badge badge-dark">3</span>
</div>
</div>
<div class="col-sm-4 more-share">
<i class="icon-share"></i> Share
</div>
</div>
<div class="row comments">
<div class="col-sm-12">
<ul>
<li class="clearfix">
<div class="clearfix">
<div class="info">
<div class="name"><strong class="primary-font"></strong></div>
<div class="date"></div>
</div>
<p>
comment 1
</p>
</div>
</li>
<li></li>
</ul>
</div>
</div>
<div class="row share">
<div class="share-facebook">
<i class="fa fa-facebook"></i>
</div>
<div class="share-twitter">
<i class="fa fa-twitter"></i>
</div>
<div class="share-google">
<i class="fa fa-google-plus"></i>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endfor %}
</section>
Could you point me to the right direction?
thank you
There is no need to modify async.html.twig. You just need to add the following code in your twig view:
{% include 'FOSCommentBundle:Thread:async.html.twig' with {'id': 'foo'} %}
To sum up, after doing the following steps:
Step 1: Setting up the bundle
Step 2: Create your Comment and Thread classes
Step 3: Import FOSCommentBundle routing
Step 4: Enable comments on a page
For the FOSUserBundle integration you just have to extend the Comment class as explained in Step 6: Integration with FOSUserBundle
I've tried half a dozen different ways to do this but i'm not sure what the issue is.
To start, here is a quick drawing of what im trying to accomplish:
What I want:
http://prntscr.com/br8xh6
whats happening:
http://prntscr.com/br8z8p
What seems to be happening is that my .row .full-row is being rendered twice, and the dynamic template is not being loaded into my <div class="col-md-10> as defined. Why would this be?
Heres my current code:
<body>
<div class="container full-container">
{{> navbar}}
{{> middle}}
</div>
</body>
<template name="navbar">
...
</template>
<template name="middle">
<div class="row full-row">
<div class="col-md-2 left-bar" style="background:#800000;">
{{> Template.dynamic template=sidebar}}
</div>
<div class="col-md-10">
{{> Template.dynamic template=content}}
</div>
</div>
<!-- </div> -->
</template>
<template name="leftbar">
<div class="row">
<div class="col-md-12">
{{> avatar size="large" shape="circle"}}
</div>
</div>
</template>
<template name="usercard">
<div class="col-md-4">
<div class="thumbnail thumb-dark">
<img src="default.png" alt="...">
<div class="caption">
<h3>Player name</h3>
<p>...</p>
Join
</div>
</div>
</div>
</template>
<template name="home">
<div class="row">
{{#each playerslooking}}
{{> usercard}}
{{/each}}
</div>
</template>
<template name="find_page">
<div style="height:150px;width:150px;background:blue;">hello</div>
</template>
JS:
FlowRouter.route('/', {
action: function() {
BlazeLayout.render("middle", {sidebar: 'leftbar', content: "home"});
}
});
FlowRouter.route('/find/:_id', {
name: 'postfind.show',
action: function() {
BlazeLayout.render('middle', {sidebar: 'leftbar', content: "find_page"});
}
});
I've refactored my code several times trying to debug this, as I'm not sure how BlazeLayout is suppose to work with nested templates.
All input appreciated, thanks.
Just in case, did you have a try at Blaze Layout root modification?
See: https://github.com/kadirahq/blaze-layout#set-different-root-node
I have inserted this nested data in my minimongo
db.orders.insert({
_id: ObjectId().str,
name: "admin",
status: "online",catalog : [{
"objectid" : ObjectId().str,
"message" : "sold",
"status" : "open"
}]
});
and i am trying to display it with this code
<template name="Listed">
<div class="row">
{{#each list}}
<article class="post">
<h3>{{_id}}</h3>
<h3>{{name}}</h3>
<br>
<h3>{{status}}</h3>
<br>
{{#each ../catalog}}
<h3></h3>
<h3>{{status}}</h3>
{{/each}}
<div class="well"></div>
<br/>
</article>
<br/><br/>
{{/each}}
</div>
</template>
but the nested data is not being displayed. How can i display the nested data?.
This is my data helper
/*****************************************************************************/
/* Listed: Helpers */
/*****************************************************************************/
Template.Listed.helpers({
'list': function(){
return Orders.find();
}
});
you need to remove ../
<template name="Listed">
<div class="row">
{{#each list}}
<article class="post">
<h3>{{_id}}</h3>
<h3>{{name}}</h3>
<br>
<h3>{{status}}</h3>
<br>
{{#each catalog }}
<h3></h3>
<h3>{{status}}</h3>
{{/each}}
<div class="well"></div>
<br/>
</article>
<br/><br/>
{{/each}}
</div>
</template>
```
I have abround 6000 documents in my mongo collection, which I need to load up into meteor client upon app startup.
In my routes (located under app/client), I have this:
Router.map(function() {
this.route('home', {
path: '/',
template: 'dashboardWrapper',
waitOn: function() {
return Meteor.subscribe('nasdaq');
},
cache: true
});
});
My dashboardWrapper template looks like this:
<template name="dashboardWrapper">
{{#if Template.subscriptionsReady}}
{{> dashboard}}
{{/if}}
</template>
My dashboard template looks like this:
<template name="dashboard">
<div class="container">
<h2>Priority - 1 Incidents Over Time</h2>
<div class="row">
<div id="yearly-bubble-chart" class="dc-chart">
<strong>Yearly Performance</strong> (radius: fluctuation/index ratio, color: gain/loss)
</div>
</div>
<div class="row">
<div id="gain-loss-chart">
<strong>Days by Gain/Loss</strong>
<a class="reset" href="javascript:gainOrLossChart.filterAll();dc.redrawAll();" style="display: none;">reset</a>
<div class="clearfix"></div>
</div>
<div id="quarter-chart">
<strong>Quarters</strong>
<a class="reset" href="javascript:quarterChart.filterAll();dc.redrawAll();" style="display: none;">reset</a>
<div class="clearfix"></div>
</div>
<div id="day-of-week-chart">
<strong>Day of Week</strong>
<a class="reset" href="javascript:dayOfWeekChart.filterAll();dc.redrawAll();" style="display: none;">reset</a>
<div class="clearfix"></div>
</div>
<div id="fluctuation-chart">
<strong>Days by Fluctuation(%)</strong>
<span class="reset" style="display: none;">range: <span class="filter"></span></span>
<a class="reset" href="javascript:fluctuationChart.filterAll();dc.redrawAll();" style="display: none;">reset</a>
<div class="clearfix"></div>
</div>
</div>
<div class="row">
<div id="monthly-move-chart">
<strong>Monthly Index Abs Move & Volume/500,000 Chart</strong>
<span class="reset" style="display: none;">range: <span class="filter"></span></span>
<a class="reset" href="javascript:moveChart.filterAll();volumeChart.filterAll();dc.redrawAll();"
style="display: none;">reset</a>
<div class="clearfix"></div>
</div>
</div>
<div class="row">
<div id="monthly-volume-chart">
</div>
<p class="muted pull-right" style="margin-right: 15px;">select a time range to zoom in</p>
</div>
<div class="row">
<div>
<div class="dc-data-count">
<span class="filter-count"></span> selected out of <span class="total-count"></span> records | Reset All
</div>
</div>
<table class="table table-hover dc-data-table">
</table>
</div>
<div class="clearfix"></div>
</div>
</template>
The relevant part of Meteor.client looks like this:
if (Meteor.isClient) {
var ndx,data;
Template.dashboardWrapper.onCreated( function() {
var template = this;
template.subscribe("nasdaq");
});
Template.dashboard.onCreated( function() {
data = Nasdaq.find().fetch();
ndx = crossfilter(data);
});
Template.dashboard.onRendered(function(){
var self = this;
self.subscribe("nasdaq", function() {
self.autorun(function() {
data = Nasdaq.find().fetch();
});
});
What I expect from this, is for the dashboard template to wait until all the data from the Nasdaq collection loads up.
What happens is absolutely nothing - no data and no errors.
If I remove ironRounter all together, and refresh, I can get a couple of dozen records (out of 6000 total).
Is there a way reliably force the app to wait until every single document loads up?
Try subscribe right before load the current template, may be it will work.
Router.route('/dashboardWrapper/:_id', {
name: 'dashboardWrapper',
waitOn: function () {
return [
Meteor.subscribe('nasdaq')
];
},
data: function () {
return Nasdaq.findOne(this.params._id);
}
});