Twig get an option in url - twig

in a form i would like modify my url when i change my select option.
When i do this, i have this in my url :
?extension-filter=&extension-list=1019
And i try to get 'extension-list' for give this parameter in my path.
Something like this is possible ? :
<form action="{{ path('my_path', {myoption : app.request.attributes.get('_extension-list') }) }}

You can retrieve a param in query string as follow:
app.request.get('_extension-list')
Hope this help

Related

Liferay friendly url with optional param

My URL have some params, so i use friendly URLs to solve that ugly URL liferays generates by default.
couple of this params sometimes are empty, that mean its no needed, but other times give me some ID i use for a query.
Example param not null:
https://myliferay.com/example-portlet/-/example-portlet/search/idTable-7
//it works
Example null param:
https://myliferay.com/example-portlet/-/example-portlet/search/idTable-null
//it works
With null param it works, but i dont like to see a null on my URL.
I want something like "":
https://myliferay.com/example-portlet/-/example-portlet/search/idTable-
//Doesnt work
But it doesnt work, its like the URL doesnt match the friendly URL pattern when a param its empty.
<route>
<pattern>/search/idTable-{idTable}</pattern>
<generated-parameter name="idTable">{idTable}</generated-parameter>
<implicit-parameter name="p_p_lifecycle">0</implicit-parameter>
<!--more implicit params-->
</route>
How can i specify optionality of a parameter?
Its like all vars of friendly url use a regex. You can change/override this regex like this: {idTable:\d}
<route>
<pattern>/search/idTable-{idTable:.*}</pattern>
<generated-parameter name="idTable">{idTable}</generated-parameter>
<implicit-parameter name="p_p_lifecycle">0</implicit-parameter>
<!--more implicit params-->
</route>
i used .* as regex for 0 or more characters, but i dont know if it will bring me problems later. If anyone knows why is not a good idea to use that regex comment it please.
Upgraded the regex with \d* to search only digits or empty: {idTable:\d*}
Info: Making URLs friendlier 7.0

How do I access embedded Mongodb document through Jade and NodeJS?

I can obtain a non embedded field from my document through jade by doing:
each user, i in gauss_buff
tr
td #{user.build_num} // where build_num is an element in my document.
However, how should one access an embedded document via Jade. Doing
user.embedded_doc_name.field
didn't work.
I used #{user.not_embedded_field} and I receive:
{
"not_embedded_field" : not_embedded_field_value,
"embedded_document": [{
"embedded_field1" : some_value
"embedded_field2" : some_other_value
I have hunted around, but can't find how to do this anywhere. Any tips would be appreciated.
Then use it like an array: #{user.embedded_document[0].embedded_field1}

how to put opencart 2.0 customer first name and last name on header?

Can anyone please tell me how to put customer's first and last name into the header in OpenCart 2.0?
I am already using this code for OpenCart 1.5.6:
<?php echo $this->customer->getFirstName(); ?>
<?php echo $this->customer->getLastName(); ?>
But this code is not working for OC 2.0
I am getting this error : Undefined property: Loader::$customer in header.tpl
Please help me anyone.
To fix this error you need to call them in the controller instead of in the template.
In catalog/controller/common/header.php add the following code inside the index() function:
$data['customer_firstname'] = $this->customer->getFirstName();
$data['customer_lastname'] = $this->customer->getLastName();
In catalog/view/theme/your-theme/template/common/header.tpl you can echo the first and last name:
echo $customer_firstname;
echo $customer_lastname;
Note that it is better not to edit Opencart core files. Instead you can use VQMod to implement the changes in the header controller.
Hey I had a solution to add first name last name of logged in user :
1.Go To: catalog/controller/common/header.php
Then find public function index () {....
Then add the following code:
if ($this->customer->isLogged()) {
$data['welcome_message'] = sprintf("Welcome %s %s, Enjoy your stay!", $this->customer->getFirstName(), $this->customer->getLastName());
}
Now go to : catalog/view/theme/YOURTHEME/template/common/header.tpl
then put this where you want :

jQuery-Validation-Engine -- Making sure fields values do not equal

I'm using jQuery-Validation-Engine to do some client side checking before sending a form to the server.
I know you can check to make sure two fields match using validate[equals[fieldId]] where fieldId is the id of the field you want to match. Useful if you want to make sure passwords match, for example.
Now I am trying to find a way to make sure fields don't match. For example, if I wanted to make sure a password field did not match a username field.
Has anyone been able to get this to work? Any other ideas?
Thanks.
After some research and trial and error, I answered my own question. I'll post what I did here so others who need to do the same thing will have a reference.
Turns out you need to create a new custom function in much the same way you add a custom regex. How to apply a custom regex is fairly well documented, but there's not much on how to implement a custom function (without calling a 3rd party function).
Digging around in the language file gives a better idea of how to handle it.
I had to create a custom validator with a function attached inside the language file (in this case jquery.validationEngine-en.js):
"notEqual": {
"func": function(field, rules, i, options){
return (field.val() == $('#username').val()) ? false : true;
},
"alertText": "* Username and password must be different"
},
In my html markup, I use it like this:
<input type="hidden" name="username" value="yourPassword" id="username"/>
<input class="validate[custom[notEqual]]" type="password" name="confirmPassword" value=""/>
Hope that helps someone.
Thanks for the help. You can also do this using funcCall.
In your case the HTML is:
<input class="validate[funcCall[notEqual]]" type="password" name="confirmPassword" value="">
and the function is:
function notEqual(field){
if(field.val() == $('#username').val()){
return "* Username and password must be different";
}
}
This might be useful for times when you have validation functions that can be re-used from other libraries or other areas of your code.
http://posabsolute.github.io/jQuery-Validation-Engine/#validators/funccall-methodname

Changing an ExpressionEngine Plugin's Parse Order

I have the following ExpressionEngine code in a template:
{exp:hits:count_hits_image entry_id='{exp:test:getpage tag="id"}'}
Where exp:test is a plugin I created to get a channel entry's ID.
The problem I'm having is that exp:hits is being parsed before exp:test, which makes the whole tag disfunctional.
What can I do to tell ExpressionEngine to parse the inside tag first {exp:test}, before parsing the outside tag {exp:hits}?
What you need to do is turn your plugin into a tag pair, so it works like this:
{exp:test:getpage tag="id" parse="inward"}
{exp:hits:count_hits_image entry_id='{id}'}
{/exp:test:getpage}
In your plugin you'd do something like this:
$vars = array();
$vars[0]['id'] = $results->row('id');
return $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, $vars);
Try this:
{exp:hits:count_hits_image entry_id='{exp:test:getpage tag="id"}' parse="inward"}

Resources