Merge new GET param with current route in Twig - symfony

I have a question. I'm creating a view file for product listing which have filter function. For example, My current Url is
mysite/category/electronics?p=1
And in my template I have a tag to add a some filter criteria. When click on a, I want my uri will be mysite/category/electronics?p=1&c=2 for example.
But I don't know what's the best practice to generate href for a tag, by current uri(app.request.uri) or generate uri from route (use path())..... Waiting for help!

Let's say you are on the route name product_show I'd say you should use path()
path("product_show", { p : 1, c : 2, i : "another_parameter"})
PS: If you have a large amount of parameters your should use url_encode to make it more readable.
Ref: http://twig.sensiolabs.org/doc/filters/url_encode.html#url-encode
And finally and good to know. app.request.query.all will give you all current query parameters in your current url.

Related

QueryBuilder and path

I'm using Adobe AEM, and I can't fetch the informations I want from the repository with the QueryBuilder.
I could reproduce my problem with the servlet.
When I enter this URL :
http://localhost:4502/bin/querybuilder.json?path=/content/geometrixx/en/products/triangle&type=cq:Page
It returns 2 results : Features and Overview.
But I would like the query to also return Triangle which is a cq:Page.
Can you help me plz ?
Thanks.
This is because, Querybuilder would search only the subtree if the path property alone is set.
In case you want to include the given path too in the search, then you need to add path.self=true to the request.
http://localhost:4502/bin/querybuilder.json?path=/content/geometrixx/en/products/triangle&type=cq:Page&path.self=true
For more info on Path Predicate, refer this (updated link).

wordpress dynamic permalink point to a page that takes URL get parameters

I want a structure such as www.training.com/courses/course/location where course and location change to a course name and a geographical location to dynamically translate to www.training.com/course/?course=course&location=location
The reason is I have a plugin to display course information based on course name and location that takes get parameters.
P.s. I don't want to manually add links into a .htaccess file to achieve this.
Are the courses and locations associated with each other? If so...
I'd recommend a custom post type for "courses," with a custom, non-hierarchical taxonomy attached, and then use a custom field in that post type to attach the location information to each course.
The Types plugin would handle all of these things relatively easily (but you'd need to create a template to display that information, of course).
If the URL structure is going to be predictable, you could try:
// $url = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
$url = "www.training.com/course/?course=course&location=location";
$array = explode('/',$url);
$rev_array = array_reverse($array);
$location = $rev_array[0];
$course = $rev_array[1];
Then edit the plugin code slightly to read these variables rather than get variables.

in drupal 7, how to get node id from url in the view?

I want to add a comment form to my view by adding
$node->nid), 'comment');
?>
however, it shows up a error saying undefined variable $node->nid, then I realize it is a view not a content type
In the view, by choosing the right url, for example, /projects/{username}/{nodeid}, I only show one content.
so I guess I can get the node id by parsing the 3rd argument of the url, so question might be how to get node id from url in the view
On views page /projects/{username}/{nodeid} <?php print arg(2);?> will give you node id.
Meany nodes can have the same title, you need to use another way, for examlple /projects/{username}/{nodeurl}. But i can't understand why you use views to display single node? For each node you can create specific patern (just like /projects/{username}/{nodetitle}) for url with module http://drupal.org/project/pathauto then costomize output of the node including comments form and other parts.

How do I list all nodes created by user specified in argument using Views in Drupal?

I have been trying to create a page using views that will list down all the nodes authored by a specific user.
The user name will be specified in the path (like - stuff/[user-name] )
Can someone please tell me how to do this using Views.
I am stuck on a dead end
for the views url path specify: stuff/%
in the arguments section add: user -> user: name
Should do it, but I'm not sure if it isn't buggy (see this issue: http://drupal.org/node/744468)
If you use user:id instead of username, you will be fine.

Drupal 6 Views 2 using Node Path as an argument

Please consider helping a Drupal noob who is in danger of tearing out what hair I have remaining.
I have a view that I want to add an argument to so that it only displays the details of the specified product. Since I'm using URL aliasing the argument is in the form of shop/product1, shop/product2 etc. However, when I go to add an argument node path (which is what I have set to shop/product1 etc is not listed) the only I could use is Node: Nid but that doesn't work because my argument is not a node id but a path alias.
The workaround I've been using is to create a CCK field to store my node path and then create an argument using the CCK field. Is this the only option?
Regards,
Sean
One way to do this would be to create a custom module and define your own callback which would then work out the NID from the path and pass that as an argument to the view using views_embed_view.
There are some contrib modules which allow you to filter by PHP code which would probably do as well.
I believe you can still use NID as the argument, as that is what's in the actual path even though you are displaying an alias in the address bar.

Resources