1

I would like to create a link to another page in my plugin and send a specific ID with it but I don't really know how to do it in craft and twig.. I spend too much time on that little task and searched in the internet but could not really find something.

In my template I have

//loop through all database entries
{% for val in entries %}
    .....
    <a href="{{ url('pluginName/editEntry/' + val.id) }}">Edit</a>
    .....
{% endfor %}

But it does not really work. How can I pass a specific id in my url and how can I receive this parameter in my php backend? I didn't find something like craft()->request->getGetVar()and my $_GET is always empty. Of course I could just take the URL and use subtring and explode to get the correct value but I'm not sure if this is the intended way

4

Use the ~ symbol to concat strings.

//loop through all database entries
{% for val in entries %}
    .....
    <a href="{{ url('pluginName/editEntry/' ~ val.id) }}">Edit</a>
    .....
{% endfor %}
| improve this answer | |
  • thank you, could you tell me if there is a better way to get the id in php except craft()->request->getUrl(); and exploding the string? – Robin Schambach Nov 9 '16 at 14:07
  • There is a a cheat sheet: straightupcraft.com/articles/cheat-sheet-craft.request . Maybe craft->request->getSegment(n); – spAnser Nov 9 '16 at 14:24
  • I already saw that but I don't know how to use it... getSegment is always null... seems like I'll just use the substring method – Robin Schambach Nov 9 '16 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.