I am using smarty in my symfony3 application.
I would like to generate an url with parameters in smarty based on symfony routing-system:
Activate
This part creates a normal url like:
http://example.com/activation
What i would like create:
http://example.com/activation?key=param
Anyone knows how to create these params and pass them to the url?
Thanks and Greetings!
Try:
{{ url('activation', {'key':'param'}) }}
Related
I get into trouble when I would like to store the image_url for updating the picture of my product. The flask extensions that I used are flask-reuploaded and flask-wtf. I have tried to search a lot but still cannot figure out a solution. Could you help me, please?
This is my app.py:
#app.route('/admin/add', methods=['GET', 'POST'])
def add():
form = AddProduct()
if form.validate_on_submit():
image_name = photos.save(form.image.data)
image_url = photos.url(image_name)
return '<h1>{}</h1>'.format(image_url)
return render_template('admin/add-product.html', admin=True, form=form)
I also include <form method="POST" action="{{ url_for('add') }}" enctype="multipart/form-data"> in my template but it doesn't help.
The error message is that werkzeug.routing.BuildError: Could not build url for endpoint '_uploads.uploaded_file' with values ['filename', 'setname']. Did you mean 'product' instead?
Thank you in advance, everyone.
I had the same issue and managed to fix it this way. I am sure someone who is way better at Python can give an explanation to what I did to fix it.
The problem is this blueprint route is not registered: _uploads.uploaded_file. I set this config item UPLOADS_AUTOSERVE=True
This allows the default route in flask_uploads.py to be used. I didn't bother with this, but it also looks like you could set the base_url in the UploadConfiguration. The class says
:param base_url: The URL (ending with a /) that files can be downloaded from. If this is None, Flask-Reuploaded will serve the files itself.
Also, I would add, you don't need to save the url. You can do upload_set.url(filename). Or upload_set.path(filename) if you wanted to modify it with a different module like PIL.
When I use the function
{%if is_granted(CLINET_ROLE) %}
By the way whene I check the base I find in colone role this
a:1:{i:0;s:11:"CLIENT_ROLE";}
You have a typo, CLINET_ROLE instead of CLIENT_ROLE
There is typo error. Correct spelling of client in twig file.
i have used laravel shortcodes (https://github.com/webwizo/laravel-shortcodes) with success, it is a nice bundle.
the question is: is there any bundle like this for symfony 3.x?
what this essentially do is take formatted string like [myString] with some optional parameters like [myString param1="abc" param2="def" ...] from a rendered blade / twig and looks for a controller / function etc. to resolve "myString". it passes the params to the controller, and the whole [...] stuff is replaced with the returned output. and it is done recursivly, so the result may contain another [myString2 ...] and so on. this is very useful in CMS building.
does anyone know anything like this for symfony?
There is a bundle that looks exactly what you are searching for:
https://github.com/mweimerskirch/MWShortcodeBundle
I'm trying to access cookies I set in my Drupal website.
I created two cookies on a form submission :
with the Drupal funtion = user_cookie_save(['myfirstcookie' => 'myfirstdata'])
with the classic PHP function = setcookie('mysecondcookie', 'myseconddata', time() + (86400 * 30), "/")
My cookies are set, no problem.
But, I didn't find how to get them (or one of them) from my Twig templates. The app.request.cookies of Symfony seems to not exist.
Do you have any idea ?
Twig has the global app helper context, via which you can access the cookies (among other things). Try this:
{{ dump(app.request.cookies) }}
And ultimately:
{{ app.request.cookies.get('MY_COOKIE_NAME') }}
Remember, cookies is an instance of ParameterBag (API), so you have to access it via get() call.
Hope this helps...
Past Cookie variable from the controller and check it. It works to me.
My code in controller is:
$data['cookie'] = $_COOKIE['postcode'];
postcode is my cookie name and in my twig templete, i write this line of code
{{ cookie }}
and show my cookie value. Thanks.
I created a parameter in my parameters file:
parameters:
category:
var: test
I can access this in PHP by fetching it like this:
$var = $this->container->getParameter('category');
$var = $var['var'];
But how can I access this parameter in my config.yml? For example, I want to pass this parameter to all my twig files as a global twig variable:
twig:
globals:
my_var: %category.var% # throws ParameterNotFoundException
(Sidequestion:
I assumed I could access it via getParamter('category.var'), but got an error there. Do you know a nicer way than my two-liner? $this->container->getParameter('category')['var'] works, but is a syntax error according to my IDE.)
$this->container->getParameter('category')['var']
..is actually a pretty good way to go. Which version of PHP is your IDE using for its syntax checking? Somebody please correct me, but I think this behavior was made valid in 5.3 or 5.4.