Results 1 to 4 of 4

Thread: Inject to blocks in templates

  1. #1
    New user
    Join Date
    10-22-15.
    Posts
    8

    Default Inject to blocks in templates

    Hi,

    Is it possible to inject, let's say, link to js file - from my own module template to some blocks in fe_page.html5? For example to $this->block('head')?

    I read this help page: https://docs.contao.org/books/manual...templates.html but it's not what I mean

    I mean my template mod_mymodule.html5
    Code:
    // I want ONLY this link inject to head block in fe_page.html5
    <script src="files/js/myscript.js"></script>
    
    rest of HTML and PHP of my own module

  2. #2
    User Andreas's Avatar
    Join Date
    07-11-09.
    Location
    Mönchengladbach
    Posts
    499

    Default

    PHP Code:
    if(TL_MODE == 'FE'// front end, or BE for back end
    {
      
    // use this path: system/modules/myModule/assets/, or: files/myFolder/

      // into the HEAD
      
    $GLOBALS['TL_CSS'][]        = 'files/css/my.css';
      
    $GLOBALS['TL_USER_CSS'][]   = 'files/css/my.css'// don't know the difference
      
    $GLOBALS['TL_JAVASCRIPT'][] = 'files/js/my.js';
      
    // files/css/_my_be.css|static - puts it in the combined file, also possible with *.js|static
      // with |static gets not combined if you're in Debug-Mode

      // further down below the HEAD
      
    $GLOBALS['TL_HEAD'][] = '<link rel="stylesheet" href="files/css/my.css">';
      
    $GLOBALS['TL_HEAD'][] = '<script src="files/js/my.js"></script>';

      
    // end of the BODY
      
    $GLOBALS['TL_BODY'][] = '<link rel="stylesheet" href="files/css/my.css">';
      
    $GLOBALS['TL_BODY'][] = '<script src="files/js/my.js"></script>';

    Web-Development, Freelancer, Burgtech, XHTML, HTML5, CSS, PHP, Javascript, MooTools, MySQL and more
    Amazon wishlist

  3. #3
    New user
    Join Date
    10-22-15.
    Posts
    8

    Default

    Thanks Andreas!

    I'm just corious - if it possible to create my own "blocks" to inject like "TL_BODY"?

  4. #4
    User Andreas's Avatar
    Join Date
    07-11-09.
    Location
    Mönchengladbach
    Posts
    499

    Default

    I think this makes no sense. CSS LINK and STYLE belongs to the HEAD although meanwhile it's allowed to place it in the BODY. If you need other places (also for JS) for your module, just stick it into your templates.
    Last edited by Andreas; 10/25/2015 at 01:43.
    Web-Development, Freelancer, Burgtech, XHTML, HTML5, CSS, PHP, Javascript, MooTools, MySQL and more
    Amazon wishlist

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •