Symfony2 - theme for multiple forms - php

Is there way to use diffrent themes for two (or more) forms on the same page.
I've 2 forms and I'd like to use theme "X" for first form and theme "Y" for second form.

You need to declare your theme before displaying your form.
You should try :
{% form_theme form 'ThemeX.html.twig' %}
{{ form(formX) }}
{% form_theme form 'ThemeY.html.twig' %}
{{ form(formY) }}
If that doesn't work (ie. second form theme declaration doesn't overwrite the first one), just use a separate template for your second form and insert it in your parent template using an include.
Try [http://symfony.com/doc/current/cookbook/form/form_customization.html#child-forms](this page) of symfony doc for more information

Related

how to display the upc in product page with opencart3?

I want to display the upc in product page with opencart 3. How do I do that?
I added the below code into my template file /catalog/view/theme/default/template/product/product.twig,but it doesn't work.
{% if upc %}
{{ upc }}
{% endif %}
Please do not forget to backup these files first.
You have to add upc as a variable to the controller first and then echo it in the template.
in order to do that:
first edit controller file:
/catalog/controller/product/product.php
and search for
$data['model'] = $product_info['model'];
after that add:
$data['upc'] = $product_info['upc'];
and save the file.
After that your code in template file that you mentioned will work.
ps: by this approach you lose these changes if you update opencart.A better approach would be to make an ocmod extension for it.

wordpress twig and gravity form

I need to put into my twig template file, in wordpress, a shortcode about my gravityform.
I read this and I've coded following lines
{% filter shortcodes %}
[gravityform id="1" title="false" description="false"][/gravityform]
{% endfilter %}
Now I see all raw html output and not my form in home page. There is any way to process gravity form short code with twig?
Thanks

Passing a field name from CFS wordpress plugin through to twig

so I'm very new to PHP and I'm having a little trouble passing a field name through.
I am using custom fields (cfs) and writing in twig for php.
Currently, I just have in my page.twig. The idea being, if an image has been set in Wordpress, the image will display in location set in page.twig.
The field name is header_image
{%if header_image %}
{{header_image}}
{% endif %}
When using Timber you can easily pass variables from your PHP controller through to your twig view. There are 2 ways to do this:
1) In functions.php you can pass variables globally to the context. The Timber Starter theme has this in it for reference. Your add_to_content function, should look like:
function add_to_context( $context ) {
global $cfs;
$context['header_image'] = $cfs->get('header_image');
Think of $context as a giant variable that passes through your variables into that actual view.
Remember: this makes your variables globally accessible, so you will need to name your CFS id's uniquely. For example global_phone_number.
2) To better structure your code, you should pass through your variables to the context, via the controller for that page. This helps ensure that you don't pass around variables that aren't being used.
In your page.twig file, you will need to add:
$context['header_image'] = $cfs->get('header_image');
Remember: the $context name is what you use in your twig file, and $cfs name is what you called it in Custom Field Suite.
Lastly:
The {% if header_image %} is good, as this will check whether a variable has been set, and then decided whether to show this block.
However, in CFS, when an image is uploaded, it gives you the option to select File URL or Attachment ID. This means you will need to handle this result in your twig file.
For example, by choosing File URL, you will need to output the {{header_image}} as:
<img src="{{header_image}}" />
You may also then want to add in the alt attribute based on the images alt text set in Wordpress media library.

October CMS - Conditionally Load a Different Page

I'm in the process of building a site in October CMS that uses a slash page. The splash page is only supposed to show to non cookied users the first time that they visit the site. I am controlling this part via a component in a plugin called splash. Here is my onRun() function:
public function onRun()
{
$key = 'shownsplash';
if(!Session::has($key) || !Cookie::get($key))
{
$this->page['showsplash'] = true;
Cookie::queue('shownsplash',true);
Session::put($key,true);
$resp = NULL;
}
}
In my main page layout called 'default' I want to conditionally load the splash page template called 'splash' using the following:
{% if showsplash %}
{{ loadpage('splash') }}
{% else %}
Regular page template
{% endif %}
Except that I'm not sure how to load a page conditionally. One additional requirement is that the splash page takes the url http://www.example.com and not any subsequent pages. Can anyone point out how to do this?
in octobercms cms/page are hit by url , the url set in the config section and are bound to a layout. so for me page are more 'routing' object than html content holder.
In fact partials ARE html content holder
So if i had to do the same thing as you mean i would use partial and page.
a page with url="/" and two partials, one for the regular page and one for the splash.
bind your plugin component to the page not the layout
{% if showsplash %}
{% partial 'home/splash.htm' %}
{% else %}
{% partial 'home/regular.html' %}
{% endif %}
I think partial are exactly what to use in this kind of conditional stuff.
generaly think of
layout as website structuration
page mainly for routing
partial for html content

How to use wordpress template is_single() in twig template

I have this include file with following code. I assume I can used wordpress is_single() to twig template file. When I tried to accessing the detail page of a wordpress post this display the word Nothing.
Even though I have a post name foo post and I did also create a rev_slider named foo post.
{% if wp.is_single('foo post') %}
{{ wp.do_shortcode('[rev_slider foo post]')|raw }}
{% else %}
Nothing
{% endif %}
Am I doing this correctly?
Your code is correct, but just be sure you have the right post title or the right post name is wp.is_single()

Categories