Jump to content

Manaus

Members
  • Posts

    209
  • Joined

  • Last visited

Posts posted by Manaus

  1. Thank you all, I checked and the value does not exist. Since the code that gives problems is used inside an included file (a header) I should foresee whatever case arises: existence or non-existence, etc.
    Da2's solution works, but I wonder if Twig crashes so easily on a typical conditional case, and if there isn't a pure Twig approach to use.

    Thanks

     

    • Like 1
  2. In my template I have set a variable called 'noindex'.

    Now, in my Twig template I cannot seem to use a conditional like this:

    {{ if page.noindex }}
    <do this>
    {{ endif}}

    because "Method Page::noindex does not exist or is not callable in this context"

    Should I put all the values within a `view` object, and pass it to the template? Is there a shortcut? I remember that within Smarty it is permissible to use `{ page->index }` within a template, and it works.

    Thank you very much

  3. Hi, I have a page where I have placed a custom field that has Lorem Ipsum as the label and lorem_ipsum as the name.
    On the page hosting that field, I would like to print the label.
    How can I do this?
    I tried `$page->lorem_ipsum->label` but it doesn't work.
    To investigate the problem further, I also tried `$page->lorem_ipsum->body`, in case there were several methods to access the various properties of the field.
    I also tried `name`, but the CMS still considers the field `$page->lorem_ipsum` as non-object.

    Can I print out the field name without going through the `$fields` object?
    Thanks

     

  4. I have never understood what the purpose of render() is.
    Sometimes I see it applied to the $page object, sometimes to an image, sometimes to an input field object.
    I searched the cheatsheet, but couldn't find much. I couldn't find any references or explanations in the forum either. Where could I learn what this method is and how it works?

    Thanks

  5. I like the syntax expressed on the ProcessWire homepage:

    echo $pages->get('/')->children->each('<li><a href={url}>{title}</a>');

    where html tags are generated only if the selector returns results.
    In contrast to such a code:

    <li><a href="<?= $page->httpUrl ?>"><?= $page->title ?></a></li>

    where the external tags are generated anyway.
    I read that `each` works for WireArrays, is there a method applicable to only one element? for example:

    echo $pages->get(10)->someMethod('<li><a href={url}>{title}</a>');

    Thanks!

  6. I'm querying 3 pages, with this code:

    <?php
    function dateToItalian($unixtimestamp) {
    	setlocale(LC_TIME, "it_IT.utf8");
    	return ucwords(strftime("%a %d %B %Y", strtotime($unixtimestamp)));
    }
    ?>
    
    <?php foreach ($page->children as $child): ?>
    <p>
      <?php
      echo $child->created." ";
      echo dateToItalian($child->created);
      ?>
    </p>
    <?php endforeach ?>

    I get this:

    • 1685722140 Thu 01 January 1970
    • 1685723334 Thu 01 January 1970
    • 1662705715 Thu 01 January 1970

    Anyone can explain why?

  7. I'm using TwigTemplateEngine for an Italian website, but I get always English dates for `{{ page.created }}` code.

    I installed the Languages Support module, Languages, Italian Language Pack, used `setlocale('LC_TIME', "it_IT")`, `setlocale('LC_TIME', "ita")`, and the various combinations with LC_ALL, but no.

    How can I output an Italian date on the page?

    Thanks!

  8. Hello, I am building a page of events, where I want to show only the coming ones.

    I tried this

    <?php 
    $theNow = new DateTime(); // ora
    
    foreach ($page->children as $child):
    
    $firstDate = new DateTime();
    $firstDate->setTimestamp( $child->event_when );
    $interval = $firstDate->diff( $theNow );
    echo $interval->s; // in seconds
    if ($interval >= 0) {
      // show article
    }
    
    ?>

    Beside returning a `Object of class DateInterval could not be converted to int` error, I ask if there is a method for displaying future events beside this.

    Thanks!

  9. I'd like to have a title field "First name second name" which is automatically composed by a "First name" and a "Second name" fields.

    For example, if I have a page with John Ford as first name and second name respectively, I'd like to have the title as "John Ford" (without quotes).

    Is it possible?

    Thanks

  10. I'm using a Datetime field for displaying event dates, and I get an English format:

    Sunday, 8 January 2023 10:00

    I put the set_locale function in the page, but no:

    <?php setlocale(LC_TIME, 'it_IT'); ?>

    How do I get a datetime in italian format?

    Thanks a lot

  11. I have a template with an "images" field. I'm trying to display it on the page, I'm using these lines, with results I do not understand.

    $page->images // teddy.jpg
    $page->images->httpUrl // void
    $page->images->url // /site/assets/files/1085/
    $page->images[0]->url // error: accessing non-object

    I thought `$page->images->url` would work, but no.

    Why is it?

  12. I cannot grasp the pattern behind the object method/properties:

    $page->hasChildren() // or $page->hasChildren ?
    $page->id(); // or $page->id ?
    $children->count() // or $children->count ?

    I mean, when to use parentheses, and when not? Is there a principle behind this?

    Usually after a couple of attempts I manage to get it working, but I'd like to have the idea come natural, without thinking.

    Thank you very much

     

  13. I set up the config file to load _main.php for each page.

    $config->appendTemplateFile = '_main.php';

    Now, I need to have one page without template loaded, for ajax purposes. Can I put some instruction on my empty.php template to not load _main?

    Thank you very much

  14. Hello, I don't grasp the use of a selector like

    $fields->get("name")

    or

    $fields->find("selector")

    I see in the cheatsheet, since when I need to print a custom field from the page I just need to write

    $page->mycustomfield

    or similar.

    How can I use the $fields object?

    Thanks!

  15. Hello, is there a method for generating a link on providing the right selector? Something like

    <?php echo $pages->get("/mypage/")->link ?>
    
    generating 
    
    <a href="/myurl/">mytitle</a>

    Instead of writing the whole string

    <?= "<a href='".$pages->get("/")->url."'>".$pages->get("/")->title."</a>" ?>
    
    or 
    
    <a href="<?= $pages->get('/')->url"><?= $pages->get("/")->title ?></a>

    Thanks!

×
×
  • Create New...