-
Posts
4,314 -
Joined
-
Last visited
-
Days Won
80
Everything posted by diogo
-
It's good to frequently test your site while not logged in. Use a different browser from the one that you use to develop, so you don't have to be always logging in and out. If you use Chrome, you can also open an incognito window for this. Anyway, to make what you asked for on the default site, change these lines on foot.inc: // If the page is editable, then output a link that takes us straight to the page edit screen: if($page->editable()) { echo "<a class='nav' id='editpage' href='{$config->urls->admin}page/edit/?id={$page->id}'>Edit</a>"; } to: // If the page is editable, then output a link that takes us straight to the page edit screen: if($page->editable()) { echo "<a class='nav' id='editpage' href='{$config->urls->admin}page/edit/?id={$page->id}'>Edit"; if($page->is(Page::statusUnpublished)) { echo "<br>Unpublished"; // this adds the unpublished status to the edit button } echo "</a>"; }
-
@arjen you are calling the repeater as if it was a normal field. What fields do you have inside it?
-
$class = $child === $page->rootParent ? " class='on'" : ''; is a short way of writing if($child === $page->rootParent) { $class = " class='on'"; } else { $class = ''; } $page->rootParent gets the ancestor that is closer to the root (a direct children of the homepage). If you change the homepage variable to a something different from the root, they will never match. For this to work you have to replace $page->rootParent for this page's ancestor that is closer to /en/. Put something like this after the first lines: foreach($page->parents as $v) { if($children->has($v)) { $newRootParent = $v; } } Then replace $page->rootParent by $newRootParent. I'm not on my computer, and I can't test this right now, so, no guarantees here
-
I think this is what you want $homepage = $pages->get("/"); $children = $homepage->children->find("visibility_in_top_menu=1");
-
It's true, I gave it a try and it worked:) It returns an array with all the segments like this: ( [1] => segment1 [2] => segment2 )
-
By the way, $input->urlSegments is not on the cheatsheet
-
I still didn't comment on this site, but I must say, I love the "Philosophie" part
-
Problem with OR statement and native page fields
diogo replied to MadeMyDay's topic in API & Templates
AND would get all the pages, while OR gets the pages from the first part, and if there isn't any, it gets the pages from the second. It seems to work as expected. You should read it like this: created_users_id|modified_users_id=1009 // get all pages that were created or the pages that were modified by this user // (if the first is true, the second doesn't run) created_users_id=1009, modified_users_id=1009 // get all pages that were created by this user, and that were also modified by this user // (both must be true) Use AND for what you want. -
put a checkbox on the main page template (it's more efficient since you don't even have to call the other page) and do this: <?php if($page->checkbox){ $item = $pages->get("template=upcoming-exhibitions"); echo "<h2>{$item->title}</h2>"; echo "<img src='{$item->exhibition_image->size(100,100)->url}' alt='$item->description'/>"; echo "<p>{$item->exhibition_summary}</p>"; } ?> Or, if you still prefer to have the checkbox on the exhibitions page: <?php $item = $pages->get("template=upcoming-exhibitions"); if($item->checkbox){ echo "<h2>{$item->title}</h2>"; echo "<img src='{$item->exhibition_image->size(100,100)->url}' alt='$item->description'/>"; echo "<p>{$item->exhibition_summary}</p>"; } ?>
-
@MadeMyDay are you still struggling with this? I came up with a solution that uses url segments... of course you would loose this functionality on your templates... You would only have to create an empty page for each language and assign it this template: <?php function toSlug($str) { $str = strtolower(trim($str)); $str = preg_replace('/[^a-z0-9-]/', '-', $str); $str = preg_replace('/-+/', "-", $str); return $str; } $lang = $page->name; $user->language = $languages->get($lang); $basePage = $pages->get("/"); $segments = $input->urlSegments; if($segments){ $page = $basePage; foreach($segments as $segment){ $children = $page->children; foreach ($children as $child){ $found = false; if($segment==toSlug($child->title)){ $page = $child; $found = true; break; } } if (!$found) throw new Wire404Exception(); } } else { $page = $basePage; } include("./{$page->template}.php"); This is all it does: Changes the language to the name of this page (page must have same name as correspondent language) For each url segment, it converts the title to a slug format, and looks for the children with the same name. On the last segment it changes the $page object to the correspondent page object. If no page is found, throws a 404. Includes the template from the original page. Maybe you could combine this with Ryan's solution for the URLs
-
Do this test to see if everything is working properly concerning security
- 21 replies
-
- 1
-
-
- installation
- problem
-
(and 3 more)
Tagged with:
-
I didn't test a lot. I really didn't do more than described on my post. But yes, with this limited test, It's working as it should.
-
Tested before and after updating. Before updating all the repeater fields were deleted when i cloned the page. After the update it didn't happen anymore.
-
I think this is how it works with Oliver's module. Also works like this with the repeatable fields. Shouldn't be too difficult to do it. They could even be hidden from editors. I still have a problem with the links. Since I replaced the $page object by the original page, $page->children, gives me the children of the English page. It would be easy to solve by creating a myPage=$page instead of replacing $page. But would be nice to do all this without even having to change the already written templates.
-
I tested the code that I posted above, and it works great I updated it with some changes that I did while testing. The navigation works like a charm with this change.
-
For email there's also swiftmailer, anyone used?
-
Best practice for staging to live database synchronization
diogo replied to evanmcd's topic in General Support
I never install a new one, Just move and change the config. -
This may seem a bit hackish, but you could have multiple trees but keeping one main tree with all the fields of all languages. The other trees would be there only for constructing the urls. There doesn't have to be any field on their pages. The template for each of those pages can call the fields from the corresponding page from the main tree. So, for having the kind of urls you want (domain.com/en/products/productA), on your template you could do this (not tested): (--Assign this template to all the pages in the language trees--) // Here I will assume that English is the default language, and the main branch of the tree $de = $pages->get("/de/"); $pt = $pages->get("/pt/"); $parents = $page->parents; // An array with all the ascendants of current page if ($parents->has($de) || $page->name == "de") { // If current page is under /de/ $lang = "de"; } if ($parents->has($pt) || $page->name == "pt") { // If current page is under /pt/ $lang = "pt"; } if (isset($lang)) { // If not the default language -> change from if($lang) to if (isset($lang)) to prevent errors // Change to the correct language $user->language = $languages->get($lang); // Now we have to convert the $page object in the correspondent page from the main tree // I'm using a pagefield now (just include a pagefield on the template and choose the corresponding page from the main tree) $page = $pages->get("$page->pagefield"); } include("./{$page->template}.php"); // includes the original template file On the head, change the navigation to: (here i used the default theme as example) $homepage = $pages->get("/"); if (isset($lang)) $homepage = $pages->get("/$lang/"); Maybe this is confusing, and maybe not easy to deal with links later, i don't know... I will sleep and see if it still makes any sense in the morning edit: I did some changes in the code, The most important are: using a select page field, including the original template, and fixing the navigation
-
Works great Ryan! And no need for the redirect in this case. Thanks! I will update the code.
-
Also Lithium looks interesting. You have a lot of work to do
-
I heard good things of http://fuelphp.com/. I glaced at their docs, and they seem good. I also heard good things about http://kohanaframework.org/, but their docs and community have the reputation of not being very helpful. Anyway, I start suspecting that you can do everything with PW
-
solved Question about setting body and headline fields
diogo replied to PHPSpert's topic in API & Templates
-
I was working over this code from apeisa http://processwire.c...t__20#entry1364 and wanted to share the result with you all. Basically, this allows you to mirror the admin form from a given page to the frontend. To give some flexibility, you can fill an array with the fields to exclude —or else, the fields to include— on the output. EDIT: I forgot to tell... this works well with regular fields (text, textareas, checkboxes, radios, multiple choice, etc), but didn't manage to make it work well with images, for instance. So, here is the code: <?php // Get the page you need to edit $mypage = $pages->get('/some/page/'); // Populate with the names of the fields you want to exclude OR include (see instructions below) // Leave empty to output all the fields $myfields = array('body', 'email'); $form = $modules->get('InputfieldForm'); $fields = $mypage->getInputfields(); // If array is not empty use it to filter the fields if ($myfields){ foreach($fields as $f){ // Output all the fields minus the ones listed in the $myfields array // Instead, to output only the fields that are in the array, remove the (!) from the condition if (!in_array($f->name, $myfields)){ $form->append($f); } } } // Else, include all the fields else { $form->append($fields); } // Add save button $field = $this->modules->get('InputfieldSubmit'); $field->attr('id+name', 'submit_save'); $field->attr('value', 'Save'); $field->label = "submit herei"; $form->append($field); // Process the form // (code replaced by a new one provided by Ryan) if($input->post->submit_save) { $form->processInput($input->post); if(!$form->getErrors()) { $mypage->of(false); // turn off output formatting before setting values foreach($mypage->fields as $f) { $mypage->set($f->name, $form->get($f->name)->value); } } } include("./head.inc"); // Render the form echo $form->render(); include("./foot.inc");
-
store the page in a variable, and get the image only later: $randomPage = $pages->get("template=artworks-child, sort=random"); $image = $randomPage->artworks_thumb->getRandom(); $thumb = $image->size(550, 0); echo "<a href='{$randomPage->url}'><img src='{$thumb->url}'></a>";