THELIA Forum

Welcome to the THELIA support and discusssion forum

Announcement

Rejoignez la communauté sur le Discord Thelia : https://discord.gg/YgwpYEE3y3

Offline


Hi everyone,

Since I my knowledge in french is not that advanced, I moved to the english part of this form for my question.
I have some trouble with my assets that are located in a module.
The assets map contians CSS, image and JavaScript files.
The first two (CSS and Images) are moved correctly to my web folder on page navigation, but the last type (Javascript) just stays in the map.
This is the folder structure in my module: http://s28.postimg.org/rjmnki4b1/image1.png

The javascript is included by used the following code
<script type="text/javascript" src="/assets/frontOffice/default/<somemodule>/js/script.js"></script>

The path wich is set in my template for the resources is correct since it works for the CSS and Images.
I'm not sure if this is a bug or I missed some configuration (?).
(PS: the documentation is not that advanced on modules and their assets).
Hope someone can help me with this problem.
Thanks in advance.

Offline


Hi

for Css you need use come this example :

{stylesheets file='assets/css/responsive.css'} <!-- folder to you css -->
        <link rel="stylesheet" href="{$asset_url}">
    {/stylesheets}

for Js you need use come this example :

{javascripts file='assets/js/myscript.js'}  <!-- folder to you js -->
    <script src="{$asset_url}"></script>
{/javascripts}

Offline


To be perfectly clear :

You have to put your templates in the module's template directory. For back-office templates, in the template/backOffice/default directory. For front-office, in the template/frontOffice/default directory.

Put your assets in one (or more) subdirectory of these directories, using the name you want (assets seems to be convenient ;-)).

\local
  \modules
    \MyModule
     \template
      \backOffice
       \default
           .. your template files ...
        \assets
         \css
             ... your css (or less) files ...
         \js
             ... your js files ...

Then, in your templates, use Thelia's assets blocks to generate your assets URLs.

The smarty 'stylesheets ' block returns the absolute URL to one of your CSS assets. The file parameter is the path to your asset file, relative to the current file path :

{stylesheets file='assets/css/mystyle.css'}
        <link rel="stylesheet" href="{$asset_url}">
{/stylesheets}

You can use a "filters" parameter in the stylesheet block, to apply some preprocessing to your CSS files. Available preprocessors are less, sass and compass. Thus, for using a less stylesheet, you'll write :

{stylesheets file='assets/css/my-less-style.less' filters='less'}
        <link rel="stylesheet" href="{$asset_url}">
{/stylesheets}

If you're using several CSS files, use '*' to add them to your template:

{stylesheets file='assets/css/*'}
        <link rel="stylesheet" href="{$asset_url}">
{/stylesheets}

As for stylesheets, there's also a javascript Smarty block,  for JS files :

{javascripts file='assets/js/myjsdir/myjsfile.js'}
        <script src="{$asset_url}"></script>
{/javascripts}

           
And another one for images :

<img src="{image file="assets/img/myimage.png"}" alt="" />

No filter is currently supported for Javascript and images blocks, but we may add some in the future, like coffee script support or image optimisations.

Last edited by roadster31 (06-03-2014 19:49:19)


OpenStudio Toulouse

Offline


Thanks for the response.
After trying to get it working for a while, I saw that the path is not relative to the template I'm using it in.
I expect the path to be: <root>/local/modules/<modulename>/templates/frontOffice/default/assets/css/style.css.
Although on runetime it's refering to <root>/templates/frontOffice/default/assets/css/style.css.

Due this problem the files I want to load are not found.
I guess I need to add a reserved variable like {$smarty.current_dir}?

Thanks in advance

EDIT: SOLVED
After going through some other plugins I found that you can set the source for the CSS and JS tag.
That fixed the issue discribed above.

Last edited by rhermans (07-03-2014 09:41:44)

Offline


After going through some other plugins I found that you can set the source for the CSS and JS tag.
That fixed the issue discribed above.

Oops. Sorry, I forgot to mention the source parameter, that should be used to load the module assets:

{stylesheets file='assets/css/mystyle.css' source='MyModule'}
        <link rel="stylesheet" href="{$asset_url}">
{/stylesheets}

Use source="name_of_your_module" to load an asset from the module template.

If "source" is not present, the main template path is used to generate the asset path.


OpenStudio Toulouse