Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to get the current parameter(s) in the URL in Volt

Is there an easy way to just get the parameter used in the URL in Volt? For example with this URL: ../client/delete/34 I just want to extract 34 - which is the id parameter. (I'm using the standard MVC routes).

Right now I'm using the below work-around with a pass through variable in the controller that works, however I'm left with the feeling that theres also a more simple way to get the parameter directly via Volt.

Been searching for an hour for a different solution but to no afail. Most topics are about getting the parameters via the controller

public function confirmAction($id)
        if(!$id) {
            $this->flash->error("Client not found");

            return $this->dispatcher->forward(["controller" => "client", "action" => "index" ]);
        $this->view->setVar('id', $id);

// view (.volt)
{% extends "layout.volt" %}

{% block title %} Clients {% endblock %}
{% block pagehead %} Client - confirm delete {% endblock %}

{% block flashMessages %} {{ super() }} {% endblock %}

{% block content %}
<div class="box box-success">
    <div class="box-header width-border">
        <h3 class="box-title">Are you sure you want to delete this client?</h3>

    <div class="box-body">
        <div class="row">
            <div class="col-xs-12">
                <a href="{{ url("client/index/") }}" class="btn btn-default" >Cancel</a>
                <a class="btn btn-danger pull-right" href="{{ url("client/delete/" ~ id ) }}" title="delete" ><i class="fa fa-trash"></i> Delete</a>
{% endblock %}


you should be able to do this.request.get('id').

otherwise you have to set them trought the controller with $this->view->setVar() ...


this.request.get('id') doesn't work. Maybe because it's not a named parameter?

edited Mar '17

Yes that's why not work. Just make it named parameter. But if it's in action as $id then it should be named parameter really.