Jump to content

Martijn Geerts

PW-Moderators
  • Posts

    2,769
  • Joined

  • Last visited

  • Days Won

    31

Community Answers

  1. Martijn Geerts's post in How to output text input in a repeater field was marked as the answer   
    // You don't need to loop the select $options = "<option value='Select Colour' selected='selected' disabled>Select Colour</option>";
    foreach($page->colour as $colour) {
    $value = $colour->colourtext;
    $options .= "<option value='" . $value . "'>" . $value . "</option>";
    }
    echo "<select id='colour'>" . $options . "</select>";

    ps, could have a bug or 2 typed in browser.
  2. Martijn Geerts's post in Field Export: send_templates was marked as the answer   
    Ok, 2.7.2 is older then say November last year, as a normal update doesn't alter the data base, and thus doesn't clean your settings it is still there, you can ignore it or remove it from the JSON object for import purposes.
  3. Martijn Geerts's post in Possible bug in Page inputfield? was marked as the answer   
    I don't see where you set:
    $field->derefAsPage == FieldtypePage::derefAsPageOrNullPage;
    When you don't set it it will store as a PageArray. 
  4. Martijn Geerts's post in Users system name field was marked as the answer   
    You could let the users log-in with their email address. You need to google around the forum to find all the things people said about it.
  5. Martijn Geerts's post in Best way to generate a consecutive number was marked as the answer   
    $max = wire('pages')->get("template=booking, sort=id");
    $lastNumber = $max->your_number_field + 1;

  6. Martijn Geerts's post in Limitation of pages with the same name was marked as the answer   
    That's true that limitation is here: https://github.com/ryancramerdesign/ProcessWire/blob/980ce4f0be2054dfbad4a7b334d35bdca42da7da/wire/core/Pages.php#L987
    That limitation is there for a good reason as you can see from the code. (needs to do a count on every iteration)
    I think it's better not to rely on automatic page name when you have that amount of pages with the same title.
    Maybe you can incorporate the creating date or something to make it more unique, and then write a while loop yourself to make it unique for that date. 
    Or set the title with the date, save the page, change the title to the wished title and save again.
  7. Martijn Geerts's post in If Page is selected, display Output was marked as the answer   
    // You need to to have the setting set: return null page if none selected.
    // When there's no page, a nullpage is returned, that page has ID 0, thus evaluates to false
    if ($myVariable->pageField->id) echo "<a href='{$myVariable->pageField->url}'>Link to Selected Page</a>";

  8. Martijn Geerts's post in PageTable: hide pages in page tree was marked as the answer   
    You could put those items in a parent under /processwire/
  9. Martijn Geerts's post in Handling Ajax form with jQuery.post was marked as the answer   
    I guess you don't POST the name submit.
    So $input->post->submit is not there, resulting in a false 
  10. Martijn Geerts's post in Mysterious WireMail was marked as the answer   
    WireMail is core and mails with the default PHP mail function,
    WireMailSmtp and WireMailSwiftMailer extends WireMail, when installed one of these will be used as mailer.

    WireMailBranding, is just a convenience Module that wraps markup around the HTML you want to send.

    Here wireMail function binds to the MailObject. (That is why wireMail() is a function call)
    https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/Functions.php#L797


    Here's the WireMail class
    https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/WireMail.php
     

    I don't understand this one use what you need if it makes sense.
  11. Martijn Geerts's post in PageTable Probelm was marked as the answer   
    Please search google for this:
    processwire Error: Maximum function nesting level 
  12. Martijn Geerts's post in <a> tag causing Internal Server Error was marked as the answer   
    It's a syntax error.
    // This is without the syntax error (note the dots and the single quotes) echo "<a class='link prev' href='" . $page->prev->url . "'>"; BTW: // Potential memory hog $pages->get(1019)->children->first() // This doesn't need to preload all children. The property boolean `true` is to count only the visible. $pages->get(1019)->numChildren(true)
  13. Martijn Geerts's post in Prevent field from updating page edit timestamp was marked as the answer   
    Looks like saving the Page 'quietly' is sufficient.
    <?php // 'quiet' => boolean - When true, modified date and modified_users_id won't be updated $pages->save($your_page, array(quiet => true));
  14. Martijn Geerts's post in Output all Fields of a Page/Template in a foreach and also output the value of the field was marked as the answer   
    Field is a field object, to get the value of the fields of the page you need to get the name of the field.
    $page->get($field->name);
  15. Martijn Geerts's post in getRendom() Image Problem was marked as the answer   
    it's ->getRandom() with an a no e
  16. Martijn Geerts's post in page listing with hidden pages not working was marked as the answer   
    I've explained your selector below:
    // Get a page with ID 1035, // Sort that page with ID 1035 (You can't sort 1 page) // include page 1035 even when it is hidden (Get will always get the page, regardless if it is hidden) // Get the children of the page with ID 1035. (Will only get the visible pages) $stellen = $pages->get("1035", "sort=sort", "include=hidden")->children; I do think you want something like this: // Find pages with the 1035 parent // Sort it // Include the hidden children $stellen = $pages->find("parent.id=1035, sort=sort, include=hidden");
  17. Martijn Geerts's post in Restrict templates of children by parent was marked as the answer   
    Yep possible, what I sometime like to do is prefixing my template names. For example:
    $templates = $this->templates->find("name^=element_"); and then returning all templates starting with element_.
    This will save me from 'forgetting' to set family settings & i'm lazy
    You could write an autoload module and Hook to:
    $this->addHookBefore('ProcessPageAdd::getAllowedTemplates', $this, 'beforeGetAllowedTemplates'); public function beforeGetAllowedTemplates(HookEvent $event) { $parent_id = $this->wire('input')->get('parent_id'); $parent = $this->pages->get($parent_id); if (!$parent->id) return; // As it is a before hook, replace it $event->replace = true; $array = array(); // All templates starting with name element_ for example $elements = $this->templates->find("name^=element_"); foreach ($elements as $template) { // Do your dingdingdong $array[$template->id] = $template; } $event->return = $array; }
  18. Martijn Geerts's post in Different templates-folder for different users/roles? was marked as the answer   
    Raymond Geerts, has pointed me a way to swap templates folder based on the hostname. (His post is somewhere here on the forum.) You need to place this code in /site/config.inc
    Here's my variation:
    /** * Switch ProcessWire templates directory on $_SERVER['HTTP_HOST']. Type the * Hostname as key and the name of the new templates folder as value. * */ $config->templates = array( 'sub.domain.dev' => 'templates-dev', // domain => templates folder name ); if (isset($_SERVER['HTTP_HOST']) && isset($config->templates[$_SERVER['HTTP_HOST']], $config->templates)) { foreach ($config->templates as $host => $folder) { if ($_SERVER['HTTP_HOST'] === $host) { $config->urls->templates = "/site/" . $folder . "/"; $config->paths->templates = dirname(__DIR__) . $config->urls->templates; } } }  Here is Raymond's post.
  19. Martijn Geerts's post in Hiding language input fields based on role was marked as the answer   
    There's no build-in mechanism to do what you want I guess. The easiest route I see is with AdminCustomFiles. 
    I would install that module, check the checkbox for config data.
    Then build your logic with the config.AdminCustomFiles object. 
  20. Martijn Geerts's post in placeholder text was marked as the answer   
    It is just a HTML5 placeholder attribute. It just shows text in a field until the field is focused. See it as a helper for editors (who are smart enough to use a modern browser)
    For the PHP part, an if statement like this will work.


    if ($page->price) {
    echo $page->price;
    } else {
    echo 'Please ask....';
    }

  21. Martijn Geerts's post in Page cannot have itself selected in a page field, causes save error was marked as the answer   
    A possible solution could be to use an other page to select but you show the current Page title. Here's how to do:
    In the Page field settings use Custom PHP code to find selectable pages
    type:
    $p = $page->parent; $p->title = $page->title; $PageArray = $pages->find("template=type-template, id!=$page->id"); $PageArray->add($p); $PageArray->sort('title'); return $PageArray; Then when the field contains the $page->parent, you know that they wanted to select the current page.
  22. Martijn Geerts's post in Somehow selector doesn't work in template was marked as the answer   
    $pages->get will not use check_access:
    $pages->get("template=shop-cart, user=40, session=6b53ec96ea298445183c269bf0d51d54, cart.product=1035, include=all, check_access=0")->id
     
    So sounds expected behaviour to me, as cart.product=1035 performs a find in the scope of the current user. And that find isn't allowed due to access rights.  
    little note: When you do a find (not get) and use include=all there's no need to call check_access=0 as that is assumed by that.
  23. Martijn Geerts's post in Creating and deleting permission settings was marked as the answer   
    I suspect that the permission returns an object (NullPage). So your if statement will be:
     

    I guess that if you append ->id to your if statement, the outcome will be the integer 0 and thus false.
     
    if($this->permissions->get('new-permission')->id) { // higher then 0, the permission (Page) does exists. } else { // 0 If not exists, the ID comes from the NullPage } ps, I didn't checked what I typed here (not on my working machine right now)
  24. Martijn Geerts's post in Pocketgrid unwanted padding was marked as the answer   
    I think the issue is that the image is by default an inline element. Inline elements do not respond the same as block elements. Verticaly you can't set paddings to 0
    You could float the image to make it a inline-block automagicly or you could make it a block element.
    img { display:block; margin: 0; } // center image with class .center img.center { display:block; margin: 0 auto; } img.left { float: left; } img.right { float: right; }
  25. Martijn Geerts's post in "Add New" drop-down menu was marked as the answer   
    There are more parents with the same template?
×
×
  • Create New...