Handlebars load template from sibling folder - templates

I have the following folder setup
templates
partials
portfolio
I would now like to include a handlebars template from portfolio into a template from partials, however it does not work.
I tried many variations of:
{{>"../portfolio/item"}}
Is there a way to do this and if so, how? Thanks.

As far as I figured out this is not possible.
However I settled for using a base layout with inlines.
This article helped me for my new approach: https://cloudfour.com/thinks/the-hidden-power-of-handlebars-partials/
I created "layouts/base.hbs" and inside used includes:
{{> portfolio/item
hero-src="http://fpoimg.com/500x200"
hero-alt="Hero 1 alt title"
}}

Related

Intraweb Template does not load the Pictures

I created an Intraweb template with single colored boxes.
When i now try to run my Intraweb Application, i can see the different slices of my template but the pictures wasn't loaded. I put it in the win32/debug folder lile its said in the documentation but the pictures are never loaded.
Any suggestions?
Thank you
Chris
[Edit]
Piece of my Html Code
<div id="Tabelle_01">
<div id="Test-01">
<img src="Bilder/Test_01.jpg" width="454" height="127" alt="">
{%IWRegion1%}
</div>
[Solution]
Adding next to the "Templates" Folder a Folder "wwwroot" and adding the Images to it and then it works.
Thanks
You did not say which version of Intraweb you are using, but in current versions Templates go in the (application)\Templates directory. Templates only modify the form, so pictures go wherever the form expects them to be. ex: your wwwroot (Application)\wwwroot.
In your case (guessing) "debug\templates" and "debug\wwwroot".
Please post your code.
Dan

How to set different application template for 404 page?

Site has traditional template structure elements: header, content, footer. And almost all pages of the site has such structure. But 404-page doesn't have the header.
So my question is: Is there some clean way to set unique application template for 404-page?
Of course, I can add {{ partial 'header' }} to the begining of all templates, beside 404-page, but I hope there is right way to do this ...
Thanx
P.S. Sorry for my English
P.S.S. EmberJS v1.9.1
Whilst not changing the application template name, you can change the content of the application template from route-to-route by observing the currentPath property of the application controller and using an {{#if}} helper in the application template to hide and show the header.
This is a cleaner approach than changing the application template name because you won't have to rerender any views.
Here is a working JS Bin.

Combining Django Templates and Polymer

I've been stuck for the past few hours trying to figure out why the core Polymer elements are not being displayed properly in a Django application I'm making to act as a personal webpage. The application at the moment just points to an index.html page which, if you follow the tutorial on Polymer, is up to step one.
However, the components are not loading on my page. The static files are all set up correctly, and there's subtle animation from the css files being loaded correctly, but the Roboto font and the core-elements are not being displayed. Running the site as a normal HTML file does everything correctly.
Is there a specific way to user Polymer in a Django template?
Thanks.
See Eric's answer to this on the polymer-dev mailing list: https://groups.google.com/forum/?fromgroups=#!searchin/polymer-dev/django/polymer-dev/N2R8qknalOI/58ZhC1gWFh4J
Relevant excerpt:
Django 1.5 has support for the verbatim tag. You can wrap your inlined element definitions in that:
https://docs.djangoproject.com/en/1.5/ref/templates/builtins/#verbatim
Example code snippet:
{% verbatim %}
<template repeat="{{item as items}}">
<my-element name="{{item.name}}"></my-element>
</template>
{% endverbatim %}
<script>
document.querySelector("template').model = {{items}}; // items here is filled by the server's template.
</script>
I'm pretty sure this has to do with the fact that Django uses the same {{}} in its templates as Polymer.
I'm adding this answer as a compliment to the already accepted answer.
You can force django to require a space for it's template tags. So for any django template tags you have to use {{ variable }} and for polymer you will use {{variable}}.
Here is a very simple module/app I created to "prepare" django for use alongside polymer.
https://github.com/andrewebdev/django-ostinato/blob/2c435dea23319be6e9011e7381afca2b4092b5a2/ostinato/polyprep/init.py
Credit goes to https://github.com/nebrybledu for this suggestion.

Applying CSS styles to ember.js handlebars template

I'm trying to create a simple Ember.js app to learn more about JavaScript MVC frameworks. However, it appears applying CSS styles to a view template isn't possible (or rather, I am ignorant of the proper way to do this):
Without template
<span class="myClass">
Some value
</span>
In this case, the style appears properly, as expected.
With template
<span class="myClass">
<script type="text/x-handlebars>
{{MyApp.someVariable}}
</script>
</span>
In this case, the style doesn't seem to be applied at all.
I even tried something like:
<script type="text/x-handlebars>
{{MyApp.someVariable classToAdd="myClass"}}
</script>
Which creates an even more bizarre output (I can't even find that element in the Chrome developer element tab).
Online tutorials don't mention this issue and I have tried researching other Stackoverflow issues (there are some about applying styles but not exactly like in this situation). Can anyone enlighten me as to what I am not doing properly?
I normally use ClassNames and classNameBindings property of Ember Views. That get the job done most of the time.
You can also try Ember layout property to wrap the template.
Found answer to this question in jquery's append() documentation
You need to convert text into html using jQuery:
template = Handlebars.compile(..);
html = template(json);
$('body').append($(html)); // <- don't forget to wrap it

Subrequests in Django templates

I'm working on my first Django project and have my templates setup with a base that all the others extend. In that base I want to have some user-specific navigation which means loading some values from the database to build the contents of a drop down menu. However I don't want to have to do this inside each view. Coming from Symfony2/Twig I would normally do this using a sub-request where I tell the template to render a view and that will use it's own template. Using syntax like:
{% render 'Bundle:Controller:action' with {} %}
How would I accomplish this same thing with Django? I've read over the docs a couple of times but can't find any way to do this.
You have two approaches:
(better)
- add the code to base.html (the one you're always extending) and only override it when you need to.
or
(worse)
- in every template use {% include %} to include your menus.html template.
Update: re-reading your question: you could modify the request in context-processor so your base.html would then have this information.
Custom template tags are what you want.