Nustache.Mvc - Is it possible to create a custom helper - nustache

I use The Nustach.MVC assembly https://www.nuget.org/packages/Nustache.Mvc3/1.13.8.22 so I can share templates betwixt back end and front.
Is there a way to write a custom handlebars helper that I can use in the back end?

Maybe this Project could help you nustache-helpers

Related

Check of Meteor Template has rendered

Is there a way to check if a specific Template has been rendered, other than by using Sessions, i.e. the Template is accessible for other external functions to use?
A good example is that I want to use Blaze.renderWithData, but need to know that the Template is availabel beforehand.
If you want to see if a template has been rendered, put a flag in the onRendered callback. If you don't like Session vars use a reactive var or dict & include the inverse in the onDestroyed. Store that reactive-whatever under your package object's global. As an alternative, if you know where it might be rendered to, you can use Blaze.getView on the element where it should appear and if it returns, you know you have it, e.g. Blaze.getView($('.foo')[0])
Also consider asking yourself why you can't use spacebars or embed the rendering directly in the onRendered callback. Using Blaze.renderWithData is fairly uncommon.

List all Twig templates used in the current request

I'm using Symfony2 with Twig templating engine.
Is there any way to output a list of all Twig templates files loaded in the current request, including the ones loaded through extends, include, etc.?
That would make my life much easier when overriding third-party bundles' blocks, but I can't find a way to do it.
I've been looking for such a tool for a long time but never found it... The debug options of twig are very limited, and there is no tool in the sf2 dev bar dedicated to it...
I always add twig or html comments on top of each of my templates to get an idea of where I am and why during development or on the final page.
You can try this code, it puts filenames in HTML like this:
<!-- START templatename.html.twig -->
...
<!-- END templatename.html.twig -->
I know, that it is not a good solution, but it is better than nothing.
not a problem when you are working in dev in app_dev.php
expand bottom SF toolbar, click on 200 status or on #your_rote_name
you will redirect to smt like localhost/_profiler/s0meha5h?panel=*
then click on left menu on TWIG then url will be like localhost/_profiler/s0meha5h?panel=twig
and you will see all templates like FolderYourBundle:Folder:twig_file_name.html.twig that loads one by one!

Accessing html.tpl.php variables from page.tpl.php

Greeting,
I am stuck with accessing $scripts variable of html.tpl.php in page.tpl.php, how to access the variable?
I am using Drupal 7
Please Help.
Thanks in Advance.
In order to alter the page's scripts, take a look at implementing hook_js_alter() in a custom module. That will allow you to perform the necessary alterations without messing with the rendered output. Further info here.
You must send explicity the variable you want to the template you want, template variables are template specific, there's no inheritance or another clean way.
The clean way is send what you need to specific template or implement a hook if it exists and does what you want.
Finally, in this case, I think you have to decide which files are loaded when hook_js_alter is called as suggested jamix.

Pretty dump variable/object in Symfony 2.*?

When developing stuff I need to output the state of some instance in order to inspect it.
While using CakePHP I always had a debug() function which does some kind of var_dump inside a <pre> html element, so the content is readable.
Is something similar in Symfony 2.x too?
exit(\Doctrine\Common\Util\Debug::dump($someVar));
use
\Doctrine\Common\Util\Debug::dump($user);
As of today, one of the best ways to debug in Symfony that I know of is the Ladybug Bundle. Its output is similar to xdebug's, but it has some nice features, like a collapsible tree structure for arays or automatically linking to documentation pages (supporting standard PHP, Doctrine and Symfony).
You can find some great examples of its use on the README.
Now there is a new function in Symfony - dump(), have a look at http://symfony.com/blog/new-in-symfony-2-6-vardumper-component

Drupal views add form to add record

I have some view which lists my module table entries.
What is the most elegant way to attach a form below the view to add record?
Waht I am trying to do know is:
I created dedicated form in my module:
function my_module_form_add_record($form_state) {
form fields.....
}
I added to the view theme file:
$add_form = drupal_get_form('my_module_form_add_record');
print $add_form;
But I do not like this solution for at least 2 reasons:
I does not work ...
2. Even if it worked - it is depended on the theme file! So if I change the theme - functionality is crashed.
I would like to find more elegant solution to attach form from custom module to the view.
I know of the existence of the "Views Attach" module but it has no option of adding custom forms.
I know also of the existence of the Views Embedded form (and I am usig it) but it is only useful if you want to add form to the every row.
Seems the must be some solution to add record from the view page!
Thanks you for help.
you could use hook_views_pre_render:
This hook is called right before the render process. The query has been executed, and the pre_render() phase has already happened for handlers, so all data should be available.
Adding output to the view can be accomplished by placing text on $view->attachment_before and $view->attachment_after. Altering the content can be achieved by editing the items of $view->result.

Resources