PYROCMS display custom image fields in page body - php

pyrocms page in Body Editor how to code for display custom fields data. like
i have a image custom field. i write code like.
{{ image:id }}
{{ page:image:id }}
{{ pages:image:id }}
{{ template:image:id }}
{{ custom_fields }}
<img alt="" class="img-custom-responsive img-border" data-pyroimage="true" src="{{ url:site }}files/thumb/{{ image:id }}/310/310/fit" />
{{ /custom_fields }}
i write this code in body Editor But this is not return image id.
How can i get image id on body Editor.
please help.
Thank you.

There is no "id" attribute for the image field type.
Check out the docs on the image field-type to see the available attributes.
Example:
{{ custom_fields }}{{ image:img }}{{ /custom_fields }} // produces a full img tag
{{ custom_fields }}{{ image:filename }}{{ /custom_fields }} // get the filename

Related

Symfony Assert doesnt working with form

I used Assert to validate fields like
#Assert\NotBlank(message="this field cannot be empty")
$private title;
#Assert\NotBlank(message="this field cannot be empty")
$private description;
#Assert\NotBlank(message="this field cannot be empty")
$private price;
Now, when Im using form in html.twig
{% body block %}
{{ form(form, {"attr": {"novalidate": "novalidate"}}) }}
{% endblock %}
everything is allright, if I have an empty field I got my message, but when Im trying to divide this form like
{% body block %}
{{ form_start(form, {"attr": {"novalidate": "novalidate"}}) }}
{{ form_widget(form.title) }}
{{ form_widget(form.description) }}
{{ form_widget(form.price) }}
{{ form_rest(form) }}
{{ form_end(form, {"attr": {"novalidate": "novalidate"}}) }}
{% endblock %}
I'm getting something like default message that I cannot add an advert, but there are no messages next to my fields. What am I doing wrong?
I've tried use novalidate attribute in every form field but it still doesn't working
You should use {{ form_row(form.title) }} instead {{ form_widget(form.title) }} and so on. Alternatively add {{ form_error(form.title) }} to every {{ form_widget(form.title) }} and so on.
Explanation: form_widget render only form control ie. input box or drop-down. form_row render: form_label - the title of field, form_widget - the control, form_error if needed - the errors attached to field. It also wrap everything on nice div to group related parts.

Symfony2 Input file photo preview

I have a form in Symfony2 and in a form i have a photo input field where after upload a photo file give me the path but i would to show the preview about photo uploaded..
This is the code of the add in the form :
->add('photo','file',array(
'attr' => array("class"=>"filestyle",
"data-iconName"=>"glyphicon-inbox",
"data-buttonText"=>"Scegli foto..",
"data-buttonName"=>"btn-primary",
"data-iconName"=>"glyphicon-folder-open"),
'label'=>'user.file.label',
'required'=>false,
)
)
How can i do for use the method onChange or can you give me the method for to show the preview of photo uploaded??
Thanks!!
You are storing file to someplace and then storing that path to database so you need to add condition for this, to display image.
You can pass image value attribute from you form with PhotoImage(file) (i am assuming your entity name is Photo) entity like this
'value' => file_exists(IMAGE_PATH.$builder->getData()->getPhotoImage()) ? $builder->getData()->getPhotoImage() : false )
here
$builder->getData()->getPhotoImage()
gives you your PhotoImage entity value if any and
IMAGE_PATH
is constant which store your root path.
now your code is sending photo path to your form now you have to get that path and display to customer, for this condition in your twig file so that you can check if value is false or not.
for this you have to render your custom form theme like described here just add this code like written bellow - link
{% if form.vars.block_prefixes[1] == "file" %}
<div class="file-box" {% if form.vars.attr.value is not defined or form.vars.attr.value %}style="background:url('{{form.vars.attr.value}}')"{% endif %}></div>
{% endif %}
{{ form_widget(form) }}
{{ form_label(form) }}
{% if form_errors(form) %}
{{ form_errors(form) }}
{% endif %}
form.vars.block_prefixes[1] == 'file' will check if it's input type file or not.
<div class="file-box"> will display your image if you have any.
Based on Nikhil Chaudhary answer, you can shows it in form:
{% if form.photo.vars.block_prefixes[1] == "file" and form.photo.vars.data %}
<img style="max-width: 100px" src="{{ asset(form.photo.vars.data) }}">
{% endif %}
You do not need check file, because the input is file, so can remove
form.photo.vars.block_prefixes[1] == "file"
block from code.
BUT if you wan't to show on change, use jQuery lib or custom function(s), like this.

Twig/Symfony not rendering form_widget

I have a twig template (home.twig), and I'm using
{{ render(controller('WebsiteUserBundle:Registration:register',{ 'template': 'popup'} )) }}
inside that template to render another template (login.twig), which is used to login the user from a popup.
The problem is that the form_widget isn't rendered, but the form_label is.
This is part of my login template:
<div class="row-fluid">
{{ form_label(form.email, 'Email:')}}
{{ form_widget(form.email, { 'attr': {'class': 'span12'} }) }}
</div>
And by "it's not rendered", I mean that there isn't even an empty div or input next to the label element in the DOM.
Why is this happening?
I had the same issue and was because I had the follow sentence before the form_widget
{{ form_rest(form) }}
Check that the form_rest be after of all your form_widget.
if you get only form_widget without extra params, like this :
{{ form_widget(form.email) }}
do you have more informations or any output ?

Pyrocms if condition is not working

this is my pyro cms code.
{{ images }}
{{ if default == 1 }}
<div><img src='{{ src }}'/>
{{ endif }}
{{ /images }}
this condition is not working when i try to print default value.
{{ images }}
{{ default }}
{{ images }}
i have two images in array. and output is return.
0 1
in array already have a default value 1. but condition is not working.
please help where i made mistake.
thank you.

Using Statamic Partial Variables within Entries Tags?

Trying to use partials in the Statamic CMS to keep some content areas as DRY as possible.
According to the documentation, I can pass variables to a partial like so:
{{ theme:partial src="sidebar" my_count="2" }}
In my partials/sidebar template, I have the following:
{{ my_count }}
{{ entries:listing folder="projects" }}
I am number {{ my_count }}
{{ /entries:listing }}
However, when the page loads, the variable inside the {{ entries:listing }} tag is not parsed.
2
I am number
I am number
I am number
I am number
I am number
Am I missing a step to get {{ my_count }} to output when called inside the entries tag pair?
NOTE: My ultimate goal is to pass the variable to a parameter, like so:
{{ entries:listing folder="projects" limit="{{ my_count }}" }}
...
{{ /entries:listing }}
The variable won't parse inside of the entries:listing tag pair, but you can use it as a parameter.
This example code works:
partials/temp.html
{{ entries:listing
folder = "blog"
limit = "{ limit }"
}}
{{ title }}
{{ /entries:listing }}
templates/temp.html
{{ theme:partial src="temp" limit="2" }}

Categories