Jump to content

Zeka

Members
  • Posts

    1,065
  • Joined

  • Last visited

  • Days Won

    11

Posts posted by Zeka

  1. @abdus Thank for your example.

    I have tried to test. It looks like I don't fully understand this approach, would be nice to get clarification. 

    Here is my setup

    In site/init.php

    wire()->addHookBefore('TemplateFile::render', function (HookEvent $event) {
    	// skip if AJAX
    	if ($event->config->ajax) return;
    
    	/** @var TemplateFile $templateFile */
    	$templateFile = $event->object;
    
    	// Skip admin pages
    	if (strpos($event->input->url, $event->config->urls->admin) === 0) return;
    
    	// check if this is a partial template, if so, stop
    	$fileDir = pathinfo($templateFile->get('filename'), PATHINFO_DIRNAME);
    	$templatesPath = $event->config->paths->templates;
    	if (realpath($fileDir) !== realpath($templatesPath)) return;
    
    	$templateName = $templateFile->page->template->name;
    
    	bd($templateName);
    
    	$prepends = [
    		'routes' => $templatesPath . "{$templateName}.routes.php",
    		'before' => $templatesPath . "_init.php" // like your _init.php
    	];
    
    	// then comes the actual template file
    
    	$appends = [
    		'after' => $templatesPath . "_main.php",
    	];
    
    	foreach ($prepends as $name => $file) {
    		if (file_exists($file)) $templateFile->setPrependFilename($file);
    	}
    
    	foreach ($appends as $name => $file) {
    		if (file_exists($file)) $templateFile->setAppendFilename($file);
    	}
    });

    In templates/categories.routes.php

    // we are only using 1 URL segment, so send a 404 if there's more than 1
    if($input->urlSegment2) throw new Wire404Exception();
    
    // we have 1 URL segment in page URL
    if ($input->urlSegment(1)) {
    	$pagename = $input->urlSegment(1);
    	$p = pages()->findOne("template=category, name={$pagename}");
    	if ($p->id) {
    		$p->render();
    	} else {
    		throw new Wire404Exception();
    	}
    }
    

    In templates/_init.php

    // Include helper methods for templates render
    require_once("./helpers/convenience-methods.php");
    require_once("./helpers/functions.php");
    
    
    region("header", renderGlobal("header"));
    region("masthead", renderGlobal("masthead", $viewData));
    region("footer", renderGlobal("footer"));
    region("scripts", renderGlobal("scripts"));

    In templates/categories.php

    $viewData["categories"] = pages("template=category");
    region("content", renderView("categories", $viewData));

    In templates/_main.php

    				<?=region("header");?>
    				<?=region("masthead");?>
    				<?=region("content");?>
    				<?=region("footer");?>

    With this setup with any URL segment1, I got render "categories " page, not "category" from $p->render();

    @szabesz Sorry for not being clear, with code examples it would be more clear what I meant.

  2. Hi.

    I'm using delayed output strategy where in "_init.php" (prepended template) file I define my default regions /fields / etc. 

    For some part of pages, I have to use URL segments and the logic of handling urlSegments is placed in templates files. 

    	$p = pages()->findOne("template=knowledge-base-category|knowledge-base-item, name={$pagename}");
    	if ($p->id) {
    		$p->render();
    	} else {
    		throw new Wire404Exception();
    	}

    In this way when $p-> id statement is true, all circle of _init.php> template file> _main.php repeats. So it takes twice as much time to render one page because a lot of heavy things happen inside _init.php which is called twice. 

    There are two ways that I see how to deal with that:

    1. Don't use urlSegments. ))) 

    2. Move heavy logic from _init.php under segments code, but in this way, I get a lot of duplicated code in my template. 

    How do you handle this cases? 

  3. 16 minutes ago, noelboss said:

    Is it somehow possible to use this in the frontend? (I'm new to PW, sorry for the question) .

    Feature Request: Also, i have the multiple field using pages that have children (nested categories). Would it be possible to visually clarify this relation? Right now all the pages are listed (which is a good thing) but the user can't tell the difference between main categories and sub categories…

    BTW, love your module, it's the easiest to use to select relations imho.

    Hi @noelboss

    You can play with "Label field" options. Select Custom format and put something like {parent.title}.

    Are you talking about front end editing? 

     

  4. 2 hours ago, Macrura said:

    can't seem to be able to init the rangeslider when the ajax loads the repeater; anyone out there know how to do this? Once there is a solution to re-init the field on the ajax opening of the repeater, that should solve the first issue.

    in terms of the 2nd question, are you saving again after loading the params?

    everything works correctly in terms of preset loading here, and not needing to change the skin; can you confirm if you saved the field after loading the new settings?

    In terms of the 2nd question. Yes, I save settings page of a field after every change. 

    Once again: 

    1. Create a text field and enable Ion Slider ( Do not load any skin or setting of the slider ). Save. 

    2. Put this field to any template. Save.

    3. Create a page with this template. Slider won't work because there are no params. Save.

    4. Load any params in the setting of the field. Save. Params are loaded and visible in textarea. Go to the page that you've created and refresh the page. Slider won't work.

    5. Change skin in settings. Save. Go to page. Slider works. 

    Here is screencast from the 3rd step. 

    slider.thumb.gif.b73efaa4b1933b2e1a2b670a61074430.gif

  5. Hi @Macrura

    Just tested the latest version from your repo and it works with repeaters partially.  

    It works in two cases:

    1. If "Repeater item visibility in editor" set to "Always open".

    2. If "Repeater item visibility in editor" set to "News items open, existing items collapsed" (default option) and you have some other field with the slider on this page, but outside of repeater items or any other dynamically loaded element.

    The same with Repeater Matrix. 

    And I have found one more strange behavior:

    1. Create field and load any predefined settings (works) 

    2. Clean settings textarea and choose any other predefined settings after that it doesn't work.

    3. Change "slider skin" setting to any other and it will work again. 

    Have tested it with Profield Textareas and it works.

     

     

  6. Hi!

    I have this code in my page template file:

    <?php namespace Processwire;
    
    if($input->urlSegment2) throw new Wire404Exception();
    
    if ($input->urlSegment(1)) {
    	$pagename = $input->urlSegment(1);
    	$p = pages()->findOne("template=knowledge-base-category|knowledge-base-item, name={$pagename}");
    	if ($p->id) {
    		$p->render();
    	} else {
    		throw new Wire404Exception();
    	}
    } else {
    	$viewData["categories"] = pages("template=knowledge-base-category");
    	region("content", renderView("knowledge-base", $viewData));
    }
    ?>

    Max urlSegments is set to 4.

    Should URL segments end with trailing slash is set to Yes. 

    Everything works as expected until I try to access any URL which ends with any special character like: 

    site.com/current-page/real-page/not-real-page)

    or

    site.com/current-page/real-page/not-real-page@

    In those cases, I get rendered homepage instead of 404 page.

    Is there something obvious that I missed? 

    • Like 1
  7. Storing user data in a session is a good way, but if the question in collecting as much user data as possible I would save every answer on each step. In that way, I will have answers from not finished quizzes/surveys.

    • Like 2
  8. @szabesz and @gmclelland

    Thank you for tests. 

    Of course, I have tried different versions of PW with and without multi language support in Opera, Chrome and IE

    Currently, I was able to track it down to this:

    1. Create image field.

    2. Set default image grid mode to square grid images ( it set by default ) and create page with this template/field

    3. When the page loads there no indication that some type of grid is selected. 

    4. Try to rename image and you get this js error.

    image_rename.thumb.gif.0b5589baaa482e138d48a9289731acbf.gif

    Then if you choose any of image grid you will be able to rename the image.

    Could you please check this behavior? 

     

     

    • Like 1
  9. 1 hour ago, OLSA said:

    Yes thinking about that, but that not decided to use that concept because in administration would be chaos (initial content is ~2000 products, but client has plan to place 10 to 20 000 products, build importers..).  Also for ajax, filters.. in backend is "easier"... "where parent category is my parent"...

     You definitely should take a look at URL segments. The power of URL segments is that your URL structure can be different from you page tree structure and in your case, as, for me, it is highly desirable.

    I think that is not a good way to place products under categories because some products can be relative to several categories. How will you handle it?

    • Like 1
  10. Hi @OLSA

    Because SEO is very important in that kind of business/site I would first of all stick to its requirements and that to other things like the usability of administration etc.d

    In your second example, you can change "showers and bathtubs" to something more general like "bathroom". In that case, you will have additions keyword in your URL. If your page name includes stop words (and, or, but, of, the, a, etc.), it's not critical to putting them in the URL. You don't have to leave them out, either, but it can sometimes help to make a URL shorter and more readable in some sharing contexts. Use your best judgment on whether to include or not based on the readability vs. length.

    As for best URL structure, I would recommend  "site.com/bathroom/showers/product". You can do it by using URL segments, so you can have desired page tree in admin and perfect URL structure on the frontend. Of course, it's much more work and there is a lot of small things like canonical links, redirect etc that you have to think about. 

    As another way to make your URL shorter you can move only last "product" part to "products", so you will have "products/product". 

    Don't forget to use schema.org or other for breadcrumbs.

     

     

    • Like 5
×
×
  • Create New...