.. _tutorial_propertyerror: The Jinja propertyerror test ============================ .. objectives:: Objectives In a :ref:`Jinja-type calculation `, it is possible to test if a variable is accessible (there is no :ref:`access_control` problem). .. prerequisites:: Prerequisites - We assume that Rougail's library is :ref:`installed ` on your computer. - It is possible to retrieve the current state of the various Rougail files manipulated in this tutorial step by checking out the corresponding tag of the `rougail-tutorials` git repository. Each tag corresponds to a stage of progress in the tutorial. Of course, you can also decide to copy/paste or download the tutorial files contents while following the tutorial steps. If you want to follow this tutorial with the help of the corresponding :tutorial:`rougail-tutorials git repository `, this workshop page corresponds to the tag :tutorial:`v1.1_140 ` in the repository: :: git clone https://forge.cloud.silique.fr/stove/rougail-tutorials.git git switch --detach v1.1_140 For now, the variable `proxy_dns_socks5` defines these access controls as follows: - if the `proxy_mode` variable is not set to `"Manual proxy configuration"` - if socks version is `v4`. .. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_131/firefox/55-proxy_dns_socks5.yml :language: yaml :caption: The :file:`firefox/55-proxy_dns_socks5.yml` In principle it works, but is that really what we want? We mean, do we want to disable it based on the proxy_mode variable? No, we actually want to make this variable available if the socks version is accessible and equals v4. Disabled a variable when an other variable is disabled ------------------------------------------------------- The most suitable syntax in Jinja for checking the status of a variable is to use the `concept of a test `_. Rougail offers a custom test that will verify correct access to the variable. This test is call `propertyerror`. Here is how one could write the Jinja using this feature: .. extinclude:: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/commit/v1.1_140/firefox/55-proxy_dns_socks5.yml :language: yaml :caption: The :file:`firefox/55-proxy_dns_socks5.yml` structure file with some Jinja code in the `hidden` property .. keypoints:: Key points We have seen that we can use the test `propertyerror` in Jinja template.