Jump to content

Zeka

Members
  • Posts

    1,065
  • Joined

  • Last visited

  • Days Won

    11

Posts posted by Zeka

  1. @Leftfield  Welcome to the community.

    The easiest and most performant way is just to make page tree reflects your desirable URL structure. But often such structure looks messy. 

    You can change it by using URL segments and rewriting page paths for your category and post templates.  

    For example, for blogs, I use such a structure

    home/blog/
    		/authors
    		/categories
    			/cat1
    			/cat2
    		/posts
    			/post1
    			/post2
    		

    I got such URLs

    site.com/blog/category/cat1
    site.com/blog/posts/post1
    etc.

    But I want to have such URLs and I want that every post can be listed in several categories, but for preventing contend duplication I want that it has only one accessible URL 

    site.com/cat1/
    site.com/cat1/post1/
    site.com/cat2/post2/

    To make it work you have to:

    1. Enable URLs segments for your home page.

    2. Create to Page Reference fields and add it to your post template

    • blog_section - Page reference field ( Page field value type set to Single page, selector 'template=blog_category') - this one we will use for building URL for the current post.
    • blog_categories - Page reference field ( Page field value type set to Multiple pages, selector 'template=blog_category')

    2. In your ready.php

    $pages->addHookAfter('Page(template=blog-category)::path', function ($e) {
    	$page = $e->object;
    	$e->replace = true;
    	$e->return = "/" . $page->name . "/";
    });
    
    $pages->addHookAfter('Page(template=post)::path', function ($e) {
    	$page = $e->object;
    	if ($page->blog_section) {
    		$slug = $page->blog_section->name;
    	} else {
    		$slug = $page->parent('template=blog')->name; //fallback
    	}
    
    	$e->replace = true;
    	$e->return = "/" . $slug . "/" . $page->name . "/";
    });

    3. In your home.php 

    if ($input->urlSegment3) throw new Wire404Exception();
    
    if ($input->urlSegment2) {
      $post_name = $input->urlSegment2;
      $match = $pages->get($sanitizer->selectorValue($post_name));
      if (!$match->id) throw new Wire404Exception();
      echo $match->render();
    	
      return $this->halt();
    }
    
    if ($input->urlSegment1) {
      $category_name = $input->urlSegment1;
      $match = $pages->get($sanitizer->selectorValue($category_name));
      if (!$match->id) throw new Wire404Exception();
      echo $match->render();
    	
      return $this->halt();
    }

    It's not tested and there can be some errors, but I hope you get a general idea. 

    • Like 4
    • Thanks 1
  2. @Roych Repeater items are also pages, but they are hidden under admin page, so they don't have URLs, but you can use URL segments for that.

    You should allow URL segments on you 'about' page template. 

    Then you can construct URL based on team repeater item id or other fields inside repeater:

     <?php $summary = truncateText($team->body); echo "$summary ...";?> <a href="<?php echo $page->url($team->id); ?>">Read more</a>

    Then on you about page template:

    if ($input->urlSegment1) {
      
      $pagename = $input->urlSegment1;
      $match = $pages->get($sanitizer->int($pagename));
      if (!$match->id) throw new Wire404Exception();
      echo $match->render();
    	
      return $this->halt();
    }

    ----------

    By the way you can use $sanitizer->truncate() to truncate your summery text

    https://processwire.com/blog/posts/processwire-3.0.101-core-updates/

    • Like 4
  3. On 11/5/2018 at 8:03 PM, dragan said:

    Did you try using a text sanitizer though?

    @dragan Yes, didn't help. Still 

    On 11/5/2018 at 3:54 PM, bernhard said:

    I'd consider this a bug

    @bernhard I have opened an issue https://github.com/processwire/processwire-issues/issues/743

    On 11/5/2018 at 10:12 PM, BitPoet said:

    The problem is that anything that looks like a ctype_digit is coerced to int in Selectors::makeSelectorArrayItem, even if you use nested array syntax and pass in the name of a sanitizer method.

    @BitPoet Thanks, yes I see, there is no way to prevent conversion to int

    
    if(is_int($value) || ctype_digit($value)) {
      $value = (int) $value;
      if($_sanitize == 'selectorValue') $_sanitize = ''; // no need to sanitize integer to string
    }

    Also, if you consider this as a bug, please, leave a comment on GitHub.

    • Like 2
  4. 7 minutes ago, ripper2600 said:
    
    if(!$yesterday_matches) {

    if return value is null.

    Yeap http://php.net/manual/en/types.comparisons.php Second line in 'Comparisons of $x with PHP functions' table. 

    Also, I have found the usage of namespaces very сonveniently, as you can delete and preload several caches at once by $cache->deleteFor("my-namespace"); and $cache->preloadFor("my-namespace");

    On one project I have used addition config variable 'disableWireCache' defined in config.php, so my statement looks like if (!$filters || config('disableWireCache')). It allows to 'disable' WireCache globaly for testing etc.

  5. @ripper2600 For sure you can use WireCache to cache number of matches. 

    $cache->preloadFor('matches');
    $today_matches = $cache->getFor('matches', 'today');
    
    if(!$today_matches) {
    	$latest_matches = $api->getLatestMatches('today');
    	$cache->saveFor('matches', 'today', $today_matches, 3600)
    }
    
    $yesterday_matches = $cache->getFor('matches', 'yesterday');
    if(!$yesterday_matches) {
    	$latest_matches = $api->getLatestMatches('yesterday');
    	$cache->saveFor('matches', 'yesterday', $yesterday_matches, 3600)
    }
    // setting
    setting([
    	'matches' => WireArray([
            'today' => $today_matches,
            'yesterday' => $yesterday_matches
        ])
    ]);

     

    • Like 3
  6. @BrendonKoz

    As you develop custom fieldtype you can add custom js file for the page inside iframe via a hook to page render method.

    $this->wire()->addHookBefore('Page::render', function ($e) {
    	$page = $e->object;
    	if ($this->input->get('modal') === 'panel') {
    		$this->wire('config')->scripts->add($this->config->urls->YourFieldType . 'your-js-file.js');
    	}
    });

    Then in 'your-js-file.js' you can directly find doms elements on the loaded page.

    Additionally, in hook, you can check whether the template of the current page (the one in the panel) has a field with your Fieldtype and then load you js.

    • Like 2
  7. Hi @BrendonKoz

    Are you developing a custom module? 

    $(document).on("pw-panel-opened", function(e) {
    	console.log('opened').
    });

    This works for me. Where do you place your code? 

    As for columns, it works for me, but only when screen larger than 1745 px. In this case, the width of the panel gets larger than 960px 

    @media (min-width: 960px)
    .uk-width-1-5\@m {
        width: 20%;
    }

    Default width of pw-panel is 50%, but you can use ' data-panel-width='60%' or ' $button->attr('data-panel-width', '100%');' to tune the width, so you will get columns on smaller screens. 

    image.thumb.png.7f4e32a6ff1d808b5e0dfec9e077dbf6.png

    • Like 3
×
×
  • Create New...