I'm using silex with a legacy application with a lot of smarty templates and also want to use the Form Provider, but the documentation has only an example to use this with Twig.
Does anyone has a small example how to render the Form to a variable that can then be displayed in a smarty template
my understanding is, that you can not render a form only by the symfony form classes.
Those classes do not have the functionality to render the form.
You need some templates that do the rendering. Those templates can be PHP or Twig.
Here is a example how to get the Form as HTML which you could then pass to the smarty template:
$html .= $silex['twig']->render('template.twig', array(
'form' => $form->createView
));
$smarty->assign('form_html',$html);
Related
I have a blade template in which all data is linked together. Now I prefer to have the HTML separated from the JS for better syntax coloring and preventing compilation when changing non-Vue HTML elements or CSS.
I've read about using #{{ vue_var }} and v-for inside Blade to reference Vue variables.
Would it be possible to load this blade template into Vue instead of defining the template above using <template></template>?
Vue components are written in javascript and blade templates are written with php. I think it's not possible.
I have a base twig template that is being extended by all the user twig templates, I have a main navigation in the base template that contains the profpic of the user, I want to pass the profpic variable to base template while rendering the index template of user via same controller.. how do I do this?
Please help..
You want make that ?
$html = $this->renderView('AccueilBundle:Reservation:billet.html.twig', array(
'reservation' => $reservation));
I'm writing a website using Slim Framework and Twig.
The sidebar on the website will have dynamically created links and i want to get the links from the database/cache every time a page is rendered, i can do this in each controller action but i would like to do this in my base template so i don't have to get and render the data manually in every controller action.
I have looked through the twig documentation and I haven't seen anything that could be of use besides the include function/tag but i don't see how i could get the data easily.
Is my only option to write an twig extension to do this or is there an easier way?
First of all: templates usually shouldn't contain any type of bussines logic but only render the data you provide it.
However you could write a custom twig function and use that to aquire the menu data from the DB in order to render it in your base template.
Alternativeley you could write some Slim middleware that aquires the data which might be able to inject the data into the template.
Hope that helps.
After reading Anticoms answer i was able to do it by writing a Twig extension.
public function getFunctions()
{
return array(
new \Twig_SimpleFunction('render', array($this, 'render'))
);
}
public function render($template, $controller, $action) {
$app = Slim::getInstance();
return $app->$controller->$action($template);
}
Now i can simply write
{{ render('Shared/sidebar.twig', 'Controller', 'Index') }}
Into my twig template to render the template with the data i want.
Note that my render() function uses slim dependency injection to instanciate the controller at runtime.
I have create a Zend Framework view helper to show a list of database results.
The view helper applies the jQuery DataTables plugin and it extends the Zend_View_Helper_FormElement.
It needs to be a FormElement because it should be wrapped by a form for pagination amongst other things.
Currently I create a Zend_Form, add the DataTables-Element and pass it to the view.
What I would really like to do is:
create an instance of the DataTables-Element and pass it to the view.
When rendering, it should wrap itself in a Zend_Form.
But: how does the DataTables-Element knows that it already is part of a Zend_Form?
In other words: the render function should also render an form-element when the element is not a part of a form.
You can use zend view helpers to render various form elements which is not parts of a form like this:
echo $this->formText('elementID', 'value', array( 'size' => 20,
'class' => 'foo')
);
There are lot of inital helpers to render form elements in zend way.
There’s no setTemplate() for components! I know but maybe there is another way to do it ?
(The question seems to be about a php framework: http://www.symfony-project.org/)
There is no setTemplate method on sfComponents. You essentially have 3 options:
Name your component the same as the partial you'd like the component to render. This may not be possible if you have multiple components you'd like to share the same template.
Create a partial with the same name of your component and include the partial there. That is, if you had a component with an executeFoo() method that you wanted to render the _bar.php template, simply call include_partial('bar', $vars) inside of _foo.php.
Load the PartialHelper and render the partial manually inside of the components execute method and have the component return sfView::NONE.
Components don't handle templates, you can only use partials. If you need to return a specific partial from inside your components class you can do something like this:
return get_partial('module/action', array('paramName' => $paramValue));
Have a look into the symfony book, chapter 7 view layer
To get around this, i'm doing:
echo get_component('module', 'action', $this->getVarHolder()->getAll());
return sfView::NONE;
This worked for me:
$this->setVar('template', 'templateName');
Obviously the template have to be in the exactly same module.