PHP Code Inside Layout File Not Executed

- 1 answer

I have a problem with some PHP code defined at the top of a layout file (default.htm) which does not executes. It is just printed verbatim on the page. The layout file is the default layout for a plugin. Here is the source file (default.htm) :

title = "default"

use Config;

function onStart() {
    $this['select2_Api_Url'] = Config::get('tudordanes.select2::select2_Api_Url');

<form action="#" method="POST">
    <div id='my-selects' >
        <label for='select-codes'>Code de loi:</label>
        <select id='select-codes' class='select2' name='select-codes'>
            <option value="">Choisir un code</option>
        <label for='select-articles'>Numero:</label>
        <select id='select-articles' name='select-articles'>
            <option value="">Numero d'article</option>

{% put scripts %}
<script type="text/javascript">
    $(document).ready(function() {
        console.log('{{ cfg_API_URL }}');        
{% endput %}


Actually, your default.htm file is in the component named 'select2' in 'tudordanes' plugin. And the rule is that you cannot access PHP code section in components. Please refer Building components instructions for the better explanation.

As per code in question, you can do with that is define onRun() function in your Select2.php file.

use Config;
public function onRun()
    $this->page['select2_Api_Url'] = Config::get('tudordanes.select2::select2_Api_Url');