Jump to content

bytesource

Members
  • Posts

    220
  • Joined

  • Last visited

Everything posted by bytesource

  1. I didn't realize this, because in the past I always choose a forum section first. This time I just wanted to start a new topic... Thanks a lot for your help! Cheers, Stefan
  2. Hi, I want to apologize in advance for going off-topic. However, I just cannot find the option to start a new thread on the forum's main page. I attached a screenshot, maybe someone else can find find the respective button. Cheers, Stefan
  3. @ Nico, Wanze Thanks a lot for your answers! I guess I have to stay with ascii path names then. Cheers, Stefan
  4. Hi, With reference to the great new multi-language page names feature, I would like to ask two questions about unicode path names: 1) Does Processwire support unicode path names, such as http://es.wikipedia.org/wiki/Automóvil and http://ru.wikipedia.org/wiki/Автомобиль ? 2) How common are unicode path names in practice? I assume Google likes them a lot, but I also realized that besides Wikipedia very few sites actually use them. Cheers, Stefan
  5. That is exactly what I was looking for! All of my side menus use the same template, and on most pages I just output parents and their children. Now all I need to do is add an additional test for the existence of a variable like 'mychildren' and process that one instead of the built-in children PageArray. So many great tips in just one thread. Once again thank you for your help! Cheers, Stefan
  6. I guess I won't forget that anymore The value of the product_category page reference is a child of the parent category I need to output. That's why the comparison inside the selector is not as straightforward as usual. if($children = $pages->find("template=offer,product_category={$category->children}")){ ... You solution is working like a charm! I did not know a selector could compare a field value against an array of values (at least not without imploding the values and placing a '|' in between each one). This is my final implementation, which essentially is your solution: $categories = $pages->find('template=categories_first_level, include=hidden'); $sub_categories = $category->children('include=hidden'); if($children = $pages->find("template=offer,product_category={$sub_categories}")){ Thank you so much for your help! Cheers, Stefan
  7. What I wanted to say is that each parent page of the WireArray (the category) has children (the product pages belonging to that category). However, I am not sure how to add children to a Page instance. At least the following code did not work: $p = new Page(); $p->set('template', 'special-offers'); $p->title = $category->title; $children = new WireArray(); foreach($pages->find('template=offer') as $offer) { if ($offer->product_category->parent->url == $category->url) { $children->append($offer); } } $p->children = $children; // This does NOT work $parents->append($p); Therefore I would like to know if a page's children cannot be set at all or if I just made a mistake. That said, your solution is much cleaner than mine and I love learning from other peoples' code. There is just one problem: I want to output the parent of the selected category. For example, if a product page belongs to category 'abc', then in the menu it should be listed under that category's parent, which in this case would be 'drilling equipment'. So the following code does not work, unfortunately (here $category is a PageArray containing the category pages 'drilling equipment' and 'titanium products'): $children = $pages->find("template=offer,product_category=$category") $category is either 'drilling equipment' or 'titanium products', but product_category always references a child of $category. So there won't be equality. Instead of using offer.product_category, I would need to refer to the selected category page's parent. I guess this requirement cannot be expressed using a selector, but I would be glad if I was wrong. Cheers, Stefan
  8. I just found a typo. The correct assignment of templates for the category pages is as follows:
  9. How to handle global variables using the API? I would like to output all javascript at the bottom of the page before the </body> tag. Right now I am somewhat ‘abusing’ the $config global variable for this, but I doubt that this is the right way to do: helpers.inc (included at the top of all templates) // variables used in main.inc $headline = ''; $content = ''; $sidenav = ''; $sidebar = ''; $config->js_config = ''; _projects.php $count = 1; echo "<ul id='filter-item'>"; foreach($page->galleries as $project) { // $page->galleries is a repeater field echo "<li data-id='id-1' class='grid_4' data-alpha='photography'>"; $gallery = new TemplateFile(wire('config')->paths->templates . 'snippets/images/single-link-gallery.php'); $gallery->set('title', $project->title); $gallery->set('id', $project->id); // id of the first image link of the gallery $gallery->set('gallery_id', $project->id); $gallery->set('images', $project->images); $gallery->set('thumb_width', 294); $gallery->set('thumb_height', 196); if($project->toggle_new) $gallery->set('new', true); echo $gallery->render(); echo "</li>"; $count++; } echo "</ul>"; single-link-gallery.php <?php $js = <<<JS imagebox.creategallery('$gallery_id', '$title', { galleryTitle: '%GALLERY%: %LIST%', continuousGalleries: 'true', }); JS; $config->js_config .= $js; ?> main.inc <script> <?php if ($config->js_config) echo $config->js_config; ?> </script> </body> Is there a better, more idiomatic way to achieve the above with the API? Cheers, Stefan
  10. I created some product categories in the page tree that are connected to a page reference field product_category: I then added the reference field to the template offer. Each product page has a side navigation that lists all products sorted by the PARENT of their selected category (in this case ‘drilling equipment’ of ‘titanium products’) The navigation function expects a page array for the menu categories. The pages children will be output as links: The code I came up with constructs a new Page object for each category. Its children need to be the product pages belonging to that category: // navigation $nav = new TemplateFile(wire('config')->paths->templates . 'snippets/sidenav-accordion.php'); $nav->set('subject', "Special Offers"); // Output folders 'drilling equipment', 'titanium products' $categories = $pages->find('template=categories_first_level, include=hidden'); // Prepare parents and children to be output in sidemenu // Subject: Special Offers // Parents' Titles: Drilling Equipment, Titanium Equipment // Children: Offers of the respective category (drilling equipment of titanium equipemnt) $parents = new WireArray(); foreach($categories as $category) { $p = new Page(); // Will be sent to sidemenu, so we need to prepare a title and its children. $p->set('template', 'special-offers'); // We have to attach some template $p->title = $category->title; // Prepare children $children = new WireArray(); foreach($pages->find('template=offer') as $offer) { // get all offers // add offer as a child of $parent if the PARENT // of its selected category (a page reference) matches $parent (= same category) if ($offer->product_category->parent->url == $category->url) { $children->append($offer); // This does work } } $p->children = $children; // This does NOT work $parents->append($p); } $nav->set('items', $parents); $nav->set('currentPage', $page); $sidenav = $nav->render(); include('./main.inc'); The above code does work - up to the point where I need to add a parent’s children. Therefore I would like to ask if there is a way to add children to a page instance using the API. Also, is constructing page instances outside the page tree an accepted practice or would it be better to approach this problem from another angle? Cheers, Stefan
  11. Thanks for explaining the need for the sanitizer in my code. I will definitely add this line.
  12. All internal links are relative links, but I just realized that I had a <base> tag in the header specifiying the default URL. After commenting this line out, typing subdomain.domain/some_page did not redirect to the main domain anymore. Thanks a lot for pointing me in the right direction! Cheers, Stefan
  13. I agree that uploading any code that gets executed on the server is always a bad idea. I just couldn't come up with a better solution. That's why I am especially gratefull for your suggestions. Following your first approach I solved the problem as follows: 1) Added field sidebar_content of type textarea to the respective templates. sidebar_content contains the names of the snippet files to be included (please see attachment). 2) Template code: <?php // Variables to be set: // $content // $sidebar include_once("./helpers.inc"); // content $t_content = new TemplateFile(wire('config')->paths->templates . 'snippets/pages/_contact.php'); $content = $t_content->render(); // sidebar $side = new TemplateFile(wire('config')->paths->templates . 'snippets/sidebar/sidebar.php'); $sidebar = $side->render(); include("./main.inc") ?> 3) Code of sidebar.php: <?php $filenames = $page->sidebar_content; if ($filenames) { $filenames = explode("\n", $filenames); foreach ($filenames as $name) { $name = trim($name); echo "<li>"; $t = new TemplateFile(wire('config')->paths->templates . "snippets/sidebar/content/" . $name . ".php"); echo $t->render(); echo "</li>"; } } ?> While the above approach is working, I am not sure if it is in any way ideomatic. Any suggestions, especially regarding the php code are highly welcome! Cheers, Stefan
  14. @ Pete You are right, using ProcessWire on the server would make thinks easier to debug. Unfortunately, my site is far from ready, so I don't want to replace it with the current site at this moment. The site I am working on is just my business site, and I don't have any other sites to play with. @ MichaMicha That was exactly the problem. Before, the rewrite rule in my .htacces file looked as follows: RewriteCond %{HTTP_HOST} . RewriteCond %{HTTP_HOST} !^www\.sovonex\.de [NC] RewriteRule (.*) http://www.sovonex.de/$1 [R=301,L] After commenting out these three lines, typing subdomain.domain.com does not redirect to www.domain.com anymore. However, clicking on any internal link on the page still redirects to www.domain.com/some_page. I attached the current htaccess file, as I could not find anything that would explain this behaviour. Maybe someone using subdomains could post their relevant rewrite rules here. Cheers, Stefan modx_htaccess.txt
  15. Hi, The content of the website I am working on needs to be available in different languages. I thought about using different subdomains for each language, like es.example.com, de.example.com. With the help of static translations and multi-language fields it should be easy to switch the language content using this code snippet: if($config->httpHost == 'es.example.com') { $user->language = $languages->get("spanish"); } To test this approach on a live server I added a subdomain temp.example.com and had it point to the root folder of my current website. The problem is that when I type in temp.example com/some_page I get redirected to www.example.com/some_page. Of course, this redirection will not work well with search engines, so I would like to ask if there is a way to stop the redirection subdomains. Additional information: The website I added the subdomain to is not a ProcessWire installation but is running on an old version of ModX. The hosting provider is Hosteurope Cheers, Stefan
  16. Apparently my solution did not work out. I also tried including the snippets into the sidebar area via page references, where each page had a template infobox that just rendered the body field of that page. However, this didn't work out either, as the body field often contains HTML and PHP code. Is there a more elegant way of choosing and displaying different sidebar content? Cheers, Stefan
  17. I include each snippet from the admin choosing its file path from the sidebar_content field of type file. No person other than my is allowed to include these files. I guess that might be the problem. The original snippets/files are stored in /site/templates/snippets/sidebar/content/, but after uploading they are pulled from /site/assets/files/a_number/.
  18. Hi, I would like to know if it is possible to turn the built-in name field into a multi-language field. This way the page name (URL) would change automatically based on the language used. Cheers, Stefan
  19. Hi, I have a field sidebar_content of type file that I use to select different snippets of code like the following: /site/templates/snippets/sidebar/content/projects_page_promotion.inc <h5>Information</h5> <section class="infobox"> <p><?php echo __("Make sure to visit our new 'Projects' page"); ?></p> </section> The snippets are included in the template as follows: <?php if ($page->sidebar_content) { foreach($page->sidebar_content as $content) { echo "<li>"; include($content->filename); echo "</li>"; } } ?> This approach works, but when the locale changes if($config->httpHost == 'es.example.com') { $user->language = $languages->get("spanish"); } the sentence in the above snippet <?php echo __("Make sure to visit our new 'Projects' page"); ?> is still shown in English, while translatable strings in other template files output the Spanish versions correctly. I would be glad if someone could point me to my error or maybe suggest a better approach. Cheers, Stefan
  20. Hi Mathew, That's how I am doing it right now. What I wanted to ask is if there is a way to just specify a folder instead of uploading every single image one by one. However, I just realized that I can select more than one image at a time, thus turning the once repetitive task of uploading images into a one-time task.
  21. Hi Everyone, I currently use the images fieldtype to upload and output images. As I sometimes need to upload many images per page, and each page's images are stored in a separate folder, I would like to know if there fieldtype that allows me to select a folder and stores its items in an array that I can loop through in the template?
×
×
  • Create New...