Jump to content

markus-th

Members
  • Posts

    62
  • Joined

  • Days Won

    1

Posts posted by markus-th

  1. <script>
          function gtag() {
            dataLayer.push(arguments);
          }
    
          gtag('consent', 'default', {
            'ad_storage': 'denied',
            'ad_user_data': 'denied',
            'ad_personalization': 'denied',
            'analytics_storage': 'denied'
          });
        </script>
        <script type="text/plain" data-type="text/javascript" data-category="statistics">
          window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
    
      gtag('consent', 'update', {
        'analytics_storage': 'granted'
      });
    </script>
     <script type="text/plain" data-type="text/javascript" data-category="statistics">
     // GTM
    </script>

    I use GTM only for Statistics, this is how it work for me.

    • Like 2
  2. 20 hours ago, kaz said:

    I do different content sections with Repeater Matrix. Since there are more and more sections, I would like to choose another solution.

    Look at this idea:

    Since I have been using this method, I no longer need any other approach to build up the content on my pages and I also need far fewer different templates.

    You don't have to use depth, but it allows extremely flexible output of content when needed.

    My basic_page template look like this:

    <?php
    
    namespace ProcessWire;
    
    include "_header.php";
    
    $items = $page->content;
    foreach ($items as $key => $item) {
        $item->position = $key;
        $item->all_items = $items;
    }
    foreach ($items->find("depth=0") as $item) {
        echo $item->render();
    }
    
    include "_footer.php";

    And all matrix "content" templates are inside the fields folder.

    image.png.42476271509179076b818c84fd23748a.png

    • Like 2
  3. 1 hour ago, MarkE said:

    I did think of that, but with multiple installations I am not confident that the id of the settings page will be identical. Maybe I’m just being overly cautious. 

    I can understand that, for me it's just always the same ID.

    Alternatively, you can also overwrite the LogoURL in admin.php.
    Directly before:

    require($config->paths->adminTemplates . 'controller.php');

    with:

    $adminTheme->logoURL = $mylogourl

    I use this for multisites where I need different logos depending on the URL.

    • Like 2
  4. 16 hours ago, MarkE said:

    The standard admin themes (UI, Rock etc) permit you to modify the logo by giving a path to it. I would like to be able to specify the logo as being an image field on a settings page? I know I could do this with a fairly ugly hack using regex in a hook on Page::render, but I wonder if there is a better way?

    I don't know if my way is better, but for me it has become standard 😉

    This is easy done:

    I set the imagepath in AdminTheme to: '/site/assets/files/1020/be-logo.svg' (1020 is my settingspage) and to make sure that the image name is always the same I use the Custom Upload Names module. Now I can simply upload a new logo and have it available in the backend.

    I exported this configuration with some fields and settings that I need again and again with the Profile Exporter from @ryan and use this as a starting point for almost every new installation.

  5. On 4/22/2023 at 4:54 PM, wbmnfktr said:

    A few days ago I saw someone mentioning ProcessWire in a comment under a WordPress-related ad on Instagram.

    That could have been me 😂

    • Like 1
    • Haha 1
  6. 1 hour ago, bernhard said:

    I thought you can simply request the whole page and HTMX will select the correct elements to replace?

    @bernhard This works pretty well for static content, but unfortunately not for content filtered by URL parameters, for example.

    I really like to use HTMX to dynamically load and replace content on pages. Also asynchronous loading of partial parts of the page becomes very easy.

    Here is a simple example of the output of a product tile with URL hook

      <?php foreach ($items as $key => $item) {
      	$pos = $start + $key + 1; ?>
      	<div :hx-get="'/getproduct/'+<?= $item->id ?>" hx-trigger="revealed" hx-indicator=".loader" class="product-tile">
          <div class"loader">
          	Some fancy loader :-)
          </div>
      	</div>
      <?php } ?>

    The hook: (getproduct.php)

    <?php 
    
    namespace ProcessWire;
    
    $wire->addHook('/getproduct/{prodid}', function ($event) {
        $id = $event->arguments('prodid');
        $item = $event->pages->get("template=product, id=$id"); ?>
    
    <div>
      <p>Producttile</p>  
    </div>
    
    <?php exit(); ?>

    And of course in ready.php

    include 'templates/functions/getproduct.php';
    
    if (array_key_exists('HTTP_HX_REQUEST', $_SERVER)) {
        $config->appendTemplateFile = '';
        $config->prependTemplateFile = '';
        $config->htmxRequest = true;
    }

    Maybe that's what @Jonathan Lahijani means by gymnastics.

    For me personally, this is not a special effort and is actually already part of my workflow.

     

    Disclaimer: I know this is not Markup Regions 😉

    • Like 3
  7. @DV-JF 

    I also had the same behavior that no core updates were displayed. This phenomenon was only with Processwire installations that were already somewhat older.

    I then noticed that the ready.php in the site folder were different for these old installations. Replacing them with a new ready.php resulted in the coreupdates being displayed again. 

    But be careful, if you already have a modified ready.php, you have to make these changes in the new file too.

     

  8. 1 hour ago, bernhard said:

    And as far as I understand hooking Session:loginSuccess is not 100% sufficient. What if a user is already logged in when you add the hook? I think the user will not get redirected in that case and will still be able to work in the backend.

    Maybe hooking before Page::render would be better

    Learned something again, thanks @bernhard for this hint. 

    • Like 1
  9.  

    1 hour ago, olafgleba said:

    I couldn't find any suitable in the module directory or hints in forum posts.

    You don't need a module, it can be done by a hook in the ready.php and an warningpage (with own template).

    -> https://processwire.com/api/ref/session/login-success/

    $this->addHookAfter('Session::loginSuccess', null, function ($event) {
        if ($this->wire('user')->hasPermission("specific_role")) {
          $session->redirect($pages->get("/warningpage")->url);
        }
    });

    On the "warningpage" log the user out with this code in the template:

    $session->logout();

     

    • Like 4
  10. On 2/4/2023 at 6:37 PM, neophron said:

    Which problems could I face with 12 subdomains and 12 users, that should have access only to their subdomain pages?

    The only problem i see is, you have to do some workarounds that each user only see his own subdomain. Otherwise all users see all sites in the adminarea.

    A hook in ready.php could look like this:

    $this->addHookAfter('ProcessPageList::find', function ($event) {
        $event->return->each(function ($p) use ($event) {
            if (!$p->editable() && !$p->addable()) $event->return->remove($p);
            else if ($p->template == 'subdomain-home' && !$this->user->hasRole("superuser") && !$this->user->hasRole(strtolower(str_replace(' ', '-', $p->title)))) $event->return->remove($p); // title from homepage and userrole have the same name
        });
    });

     

    • Like 1
  11. Since I had to update more and more projects lately and also the PHP version of some of these projects was set to >=8 in the meantime I created a fork of the module and updated mPDF to version 8.1.3.

    With only some small changes in the WirePDF module I can now continue to use Pages2PDF without any restrictions.

    Maybe this is helpful for someone.

    https://github.com/markusthomas/Pages2Pdf

    • Like 5
  12. Also tested it ... wow that's awesome. 

    Phrase: how to add a new field to a processwire template via api

    To add a new field to a ProcessWire template via the API, you can use the $fields->save() method. This method allows you to create a new field and add it to a template using a PHP script. Here is an example of how this could be implemented:

    // Use the Wire class to access the ProcessWire API
    $wire = Wire();
    
    // Get the fields and templates modules
    $fields = $wire->fields;
    $templates = $wire->templates;
    
    // Create a new field
    $field = $fields->newField();
    
    // Set the name and type of the field
    $field->name = 'my_field';
    $field->type = 'text';
    
    // Save the field
    $fields->save($field);
    
    // Get the template to which you want to add the field
    $template = $templates->get('my_template');
    
    // Add the field to the template
    $template->fields->add($field);
    
    // Save the template
    $template->save();


    In the example above, we use the $fields->newField() method to create a new field, and then use the $fields->save() method to save the field. We also use the $templates->get() method to get the template to which we want to add the field, and then use the $template->fields->add() method to add the field to the template. Finally, we use the $template->save() method to save the template with the added field.

    Note that this is just one way to add a new field to a ProcessWire template via the API. There may be other approaches that could work as well.

    • Like 1
×
×
  • Create New...