GithubHelp home page GithubHelp logo

Extending the file pattern example about templer HOT 3 CLOSED

skx avatar skx commented on September 26, 2024
Extending the file pattern example

from templer.

Comments (3)

skx avatar skx commented on September 26, 2024

Unfortunately this isn't directly supported. It is close to being supported, but due to a bug it fails - I'll report that and fix it shortly.

The best I could do is fix the bug, then write this:

     files: file_glob( "*.jpg*" )
     ----
     This is a simple image-gallery:

    <!-- tmpl_loop name='files' -->
        <!-- tmpl_if name='width' -->
            <img src= "<!-- tmpl_var name='file' -->" width="<!-- tmpl_var name='width' -->" height="<!-- tmpl_var name='height' -->">
        <!-- /tmpl_if -->
        <!-- tmpl_if name='contents' -->
             <p><!-- tmpl_var name='contents' --></p>
        <!-- /tmpl_if -->
     <!-- /tmpl_loop -->

This relies upon the FileGlob.pm behaviour which I'd forgotten about:

  • If a glob matches an image and you have Image::Size available then the variables width and height will be populated.
    • Here we use that to wrap an "if" around the image.
  • If the glob does not match an image, and does not match the templer suffix, then the contents are available as content - but this is a bug, becaues the same name is used in the layout.
    * I've just updated the code to use contents instead.

The files here are:

    deagol ~/x $ ls -1 input/
    17635184_10212309877612942_91544094097573559_o.jpg
    17635184_10212309877612942_91544094097573559_o.jpg.caption
    18278724_10155384183372342_4594716052523220387_o.jpg
    18278724_10155384183372342_4594716052523220387_o.jpg.caption
    index.skx

So the glob here matches "*.jpg*" which half the time is an image, and half the time is a caption.

from templer.

skx avatar skx commented on September 26, 2024

OK bug fixed - the example above should now work if you update to include the commit I just made, but this is a bit terrible, so you might prefer to write a plugin instead :)

from templer.

gh-4 avatar gh-4 commented on September 26, 2024

I might have a try at a plugin then, and if I can't make it work try the "terrible" way :)

Thanks for the rapid reply! I guess I'll close this as it seems a plugin is the "official" way to do it.

from templer.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.