Jump to content

Search the Community

Showing results for tags 'page'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to ProcessWire
    • News & Announcements
    • Showcase
    • Wishlist & Roadmap
  • Community Support
    • Getting Started
    • Tutorials
    • FAQs
    • General Support
    • API & Templates
    • Modules/Plugins
    • Themes and Profiles
    • Multi-Language Support
    • Security
    • Jobs
  • Off Topic
    • Pub
    • Dev Talk

Product Groups

  • Form Builder
  • ProFields
  • ProCache
  • ProMailer
  • Login Register Pro
  • ProDrafts
  • ListerPro
  • ProDevTools
  • Likes
  • Custom Development

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

  1. Hi, New to PW, please forgive my ignorance if this has been answered before, I have scoured the docs and forums but couldn't find anything. I'm trying to add a custom tab to the Page Edit screen (or process), which will contain fields for a page hero. Ideally, I would have a "Hero" tab before "Content", which would contain fields for images, text, a CTA button, etc. What I have so far is this: class HeroTab extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Page Hero', 'version' => 1, 'summary' => 'Header fields for pages.', 'singular' => true, 'autoload' => true, ); } public function ready() { if(wire('page')->process != 'ProcessPageEdit') return; $this->addHookAfter('ProcessPageEdit::buildForm', $this, 'addTab'); } public function addTab(HookEvent $event) { $form = $event->return; // create the tab $hero = new InputfieldWrapper(); $hero->attr('id+name', $this->className() . 'hero'); $hero->attr('title', $this->_('Hero')); // Images $fimages = $this->modules->get("InputfieldImage"); $fimages->attr('id+name', 'hero_images'); $fimages->label = $this->_('Images'); $fimages->extensions = 'gif jpg jpeg png svg'; $hero->append($fimages); // Text $ftext = $this->modules->get("InputfieldCKEditor"); $ftext->attr('id+name', 'hero_text'); $ftext->label = $this->_('Text'); $hero->append($ftext); $form->prepend($hero); } } This adds the tab and the fields, but after the "View" tab. However, the bigger problem is that the fields do not save. When I click Save, the page refreshes, with the "Saved Page" notice, but the fields are empty. I got inspiration from https://github.com/adrianbj/ProcessRedirectIds/blob/master/ProcessRedirectIds.module, but I think it is for the older 2.x version because it originally used $form->append which put the bottom save button between the tabs and tab content. Any help would be appreciated, I am thoroughly lost and the documentation doesn't give any examples for what I'm trying to do. Cheers
  2. Hello, I read about conditional hooks and wanted to utilize them. In the process of trying to implement them I found that they do not get called. So I reduced my hook to a minimum wire()->addHookAfter('Page::changed', function($event) { die('changed'); }); And nothing happens at all. Also with Page::changed(title) or Page(template=basic-page)::changed(title) no luck. In the code comment in Wire.php it says: "Hookable method that is called whenever a property has changed while change tracking is enabled" I see that change tracking is enabled as wire()->addHookAfter('Pages::saveReady', function($event) { if($event->arguments[0]->isChanged('title')) die('changed'); }); is working. The hookable method ___changed() in Wire.php is empty. I tried this on 2 different installs PW 3.0.61 and 3.0.62 Can anyone please confirm or let me know if I'm doing anything wrong here. Thank you.
  3. I've got this code to fetch all pages: /** @var PageArray $pages */ $pages = $this ->wire('pages') ->find(sprintf( 'has_parent!=2,id!=2|7,status<%s', Page::statusTrash )); With this I fetch all pages except admin, but that includes the 404 page as well. Is there a way to exclude pages like the 404 page from the result? Or maybe loop through the result set to check for the pages response code (without curl that is)? I want to avoid filtering the 404 page by ID if possible.
  4. Resources (Ryan's own): ImportPagesCSV FieldtypeMapMarker So I edit the accepted $fieldtypes on :76: /** * List of Fieldtypes that we support importing to * */ protected $fieldtypes = array( 'FieldtypePageTitle', 'FieldtypeText', 'FieldtypeTextarea', 'FieldtypeInteger', 'FieldtypeFloat', 'FieldtypeEmail', 'FieldtypeURL', 'FieldtypeCheckbox', 'FieldtypeFile', 'FieldtypePage', 'FieldtypeMapMarker', 'FieldtypePassword', 'FieldtypeRepeater' ); Page, MapMarker, Password and Repeater were added by me. Then alter importPageValue: /** * Assign a value to a page field * */ protected function importPageValue(Page $page, $name, $value) { $field = $this->fields->get($name); if($field->type instanceof FieldtypeFile) { $value = trim($value); // split delimeted data to an array $value = preg_split('/[\r\n\t|]+/', $value); if($field->maxFiles == 1) $value = array_shift($value); $data = $page->ImportPagesCSVData; $data[$name] = $value; $page->ImportPagesCSVData = $data; } elseif($field->type instanceof FieldtypePage) { $value = trim($value); if(wire("pages")->find("$name=$value")) $page->set($name, $value); } elseif($field->type instanceof FieldtypeMapMarker) { $value = trim($value); $page->set($name->address, $value); } elseif($field->type instanceof FieldtypeRepeater) { // } else { $page->set($name, $value); if($name == 'title') $page->name = $this->sanitizer->pageName($value, 2); // Sanitizer::translate elseif($name == 'fullname') { $page->name = $this->sanitizer->pageName($value, true); } } } Page import works with ID values, which was trivial to incorporate; passwords too. MapMarker and Repeater as you might guess do not. How can I save the map->address value? Hopefully it will update the corresponding map fields too but one thing at a time. As for the repeaters... LostKobrakai tipped me off to foreach($page->engines as $e) { foreach($e->fields as $field) { echo $field; echo $e->get($field); } } which works for their names and values, but in this function you're passed the field, and something like foreach($page->$field as $e) { foreach($e->fields as $field) { echo $field; echo $e->get($field); } } doesn't work... and what it would need to do inside anyway is check for a subfield whose name is equal to the column header (choose the repeater field itself e.g., engines in the select per repeater subfield value, e.g., engine_fueltype), then explode that cell value by pipes ('|'), and for each subvalue, populate the repeater#->subvalue... but before all that I need to be able to iterate through the subfields from the field in this function. Anyone have any ideas?
  5. How can I check if the user is in the admin enviroment of processwire? At the moment I'm using some buggy url check but I figure that there must be something in processwire itself to check for that. I don't want to check if the user has administrator privileges, just if the user is visiting an admin url. Because the admin url can be changed from the admin panel I don't want to check on something hard coded as well. What is the best way to check for an admin page?
  6. Hi all, I'm just trying to update a custom field value for a page but I noticed in the DB that the old value is still there? Rather than updating, it appears to create a new record for the updated value and increments the sort value. Why is this? Is it not possible to just overwrite the value within the DB using the API? For example: $pageObject->of(false); $pageObject->customField = "Updated Value"; $pageObject->save(); $pageObject->of(true); I would have expected the value just to be overwritten and persisted to the field table in the database? Obviously I am missing something or just not grasping why it works like this?
  7. Hi, I have created a template and will create several pages with it. One block on these pages is always the same text that I need to reuse. But it should be editable. What is the appropriate way to achieve this? I thought I might create a separate template and create a page with it. Then include that page into the other pages via a field. But I could not find a field that is working like this. Any help is appreciated!
  8. I've written a hook which replaces the page::render method. Based on a few conditions, I might want to output something different from what page::render would return. So when my conditions aren't met, I want to use the return value of the original page::render method. How can I do this? At the moment I've got something like this: function pageRenderHookMethod (HookEvent $event) { if ('my condition' == true) { $event->replace = true; $event->return = 'my custom return value'; } else { $event->return = 'original return value of page::render'; } } But I don't know how to get the original return value of page::render because the would trigger my hooked method instead of the original method.
  9. This morning I pushed a module to github which extends the page api with moving and sorting capability. https://github.com/kixe/PageMove * CALLABLE (static & instance) * PageMove::execute($page, $parent = null, $newIndex = 0, $selector = 'all'); * $modules->get('PageMove')->execute($page, $parent = null, $newIndex = 0, $selector = 'all'); * * EXTENDED PAGE API * @method $page->move($parent, $newIndex = null, $selector = 'all') * @method $page->setIndex($newIndex, $selector = 'all') // set absolute index include=all * @method $page->getIndex($selector = '') // same as $page->index without argument @see getSelector() * * @method $page->moveFirst($parent = null) * @method $page->moveLast($parent = null) * @method $page->moveForward($steps = 1, $selector = 'all') * @method $page->moveBackwards($steps = 1, $selector = 'all') * * @property $page->moveFirst // same parent * @property $page->moveLast * @property $page->moveForward * @property $page->moveBackwards * * EXTENDED PAGES API * @method $pages->move($page, $parent = null, $newIndex = 0, $selector = 'all') * @method $pages->resortChildren($page, $selectorValue) * // same like core function $pages->sort($page, true); with capibility to change the sort condition Have a nice weekend.
  10. Hi, I just wanted to check whether or not the following topic is still valid with respect to PW 3.x: https://processwire.com/talk/topic/22-how-to-build-a-news-page/ I am trying to integrate a news section into a basic multisite PW website installation (voluntary project) intended for a community of two villages. Currently there are 4 subdomains (hca-site, hfi-site, hhg-site, hps-site) that link back to the main domain website (https://thehanneys.uk) by clicking on their home buttons. I had a look at the Blog (ProcessBlog & MarkupBlog) module but it is not really what I'm looking for - a simple News section. At the moment we're just concentrating on getting the functionality in place. The styling can come later. The first issue encountered is that there is no checkbox under the Advanced section for "Page Numbers" to turn them on for the news-index template. Secondly, I don't understand why the following text is being displayed above the navigation when I expected it to be displayed after the page title. Thirdly, are the story pages displayed on the index page simply by creating a new child under News (page based on news-index.php template)? Showing 0 of 0 Article(s) | Page 1 of 0 The current code for the news-index.php template is as follows: <?php namespace ProcessWire; // basic-page.php template file // See README.txt for more information // Primary content is the page's body copy $content = $page->body; // If the page has children, then render navigation to them under the body. // See the _func.php for the renderNav example function. if($page->hasChildren) { $content .= renderNav($page->children); } // if the rootParent (section) page has more than 1 child, then render // section navigation in the sidebar if($page->rootParent->hasChildren > 1) { $sidebar = renderNavTree($page->rootParent, 3) . $page->sidebar; } // start the news stories list echo "<ul>"; // get the stories for this page $stories = $page->children("limit=6, sort=-date"); // note if you set the stories to sort by date descending on the /news/ page // in the admin, then you can omit the "sort=-date" above. // cycle through each story and print it in a <li> foreach($stories as $story) { echo " <li><a href='{$story->url}'>{$story->title}</a> <p><strong>Date:</strong> {$story->date}</p> {$story->body} </li> "; } echo "</ul>"; // get values for our placemarker headline $start = $stories->getStart(); $end = $start + count($stories); $total = $stories->getTotal(); $num = $input->pageNum; $lastNum = ceil($total / $stories->getLimit()); // output the placemarker headline echo "<h5>Showing $start - $end of $total Article(s) | Page $num of $lastNum</h5>"; // output pagination links echo $stories->renderPager(); The current code for the news-story.php template is as follows: <?php namespace ProcessWire; // basic-page.php template file // See README.txt for more information // Primary content is the page's body copy echo "<div id='bodycopy'>"; $content = $page->body; echo "</div>"; // If the page has children, then render navigation to them under the body. // See the _func.php for the renderNav example function. if($page->hasChildren) { $content .= renderNav($page->children); } // if the rootParent (section) page has more than 1 child, then render // section navigation in the sidebar if($page->rootParent->hasChildren > 1) { $sidebar = renderNavTree($page->rootParent, 3) . $page->sidebar; } P.S. Are there any books/tutorials specifically covering PW 3.x? Any assistance would be greatly appreciated.
  11. How can I change the output of `Page::render`? I've created a hook before page::render, but when I set the $event->return to something else, my whole page is replaced with that value. For example: public function beforePageRender(HookEvent $event) { $event->return = 'blaat'; } This will cause my whole page to be nothing more than just 'blaat'. What I want, is that my menu, footer etc. are still visible but only the content of that page is replaced.
  12. I'm trying to create tests using PHPUnit, and I have the following method: protected function _getRootItems(Page $currentPage) { /** @var Page $page */ foreach (wire('pages')->find("has_parent!=2,id!=2|7,status<" . Page::statusTrash . ",include=all") as $page) { if ($this->_isActivePage($page) && $page->parent_id == 1) { $output[$page->sort] = [ 'id' => $page->id, 'title' => $page->title, 'url' => $page->url, 'template' => $page->template->name, 'isActive' => $page->id == $currentPage->rootParent->id, 'children' => [] ]; } } ksort($output); return $output; } I want to write a test for this method in PHPUnit. I end up with the error: Trying to get property of non-object This is because $currentPage->rootParent is null. My test looks like this: public function testGetRootItems() { $mock = $this ->__getMock() ->disableOriginalConstructor() ->setMethods([ '_isActive' ]) ->getMock(); $mock ->expects($this->any()) ->method('_isActive') ->willReturn(false); $page = $this ->getMockBuilder(\ProcessWire\Page::class) ->disableOriginalConstructor() ->setMethods([ '__get' ]) ->getMock(); $rootParent = $this ->getMockBuilder(\ProcessWire\Page::class) ->disableOriginalConstructor() ->setMethods([ '__get' ]) ->getMock(); $template = $this ->getMockBuilder(\ProcessWire\Template::class) ->disableOriginalConstructor() ->setMethods([ '__get' ]) ->getMock(); $template->name = 'name of the template'; $rootParent->id = 1; $page->template = $template; $page->id = 2; $page->rootParent = 'hierzo!'; var_dump( $page->rootParent ); $method = $this->__getReflectionMethod('_getRootItems', $mock); $method->invoke( $mock, $page ); } I've already tried to override the rootParent with it's method (___rootParent), tried setting it directly ($page->rootParent) but so far nothing worked. I probably miss something really simple here. I know that in my example, I set the value to a string. But the result of the var_dump below it is still NULL. I also tried setting it using $page->rootParent = $rootParent, this had no effect. So my question: How can I possible override this rootParent variable?
  13. I'm confused by how Processwire should display custom fields. I have Home page set up with a field type Page (called 'blocks'), and that field has one page selected (called 'footer'), and that page contains 3 fields. The idea is that this footer page is reusable as a block on any other page, while also being fully editable in the backend (and only needing to be edited once to change on all pages). This is as close to a Drupal blocks approach as I could get. In principal, certainly from the backend, this is working fine. It's clear enough for a site editor. The issue is how to display this 'blocks' field (the page attached to it and content of fields that page contains). This system only works if I can display that field, without needing to specify or hard code the page name within the field, or fields within that page (because this may change later). The one constant will be that the 'blocks' field is always linked to selected page templates. Based on what I understand of Processwire logic, because I display the title with $page->title, I would have expected the following to work: $page->blocks or $page->fields->get('blocks') This however only returns what I presume is the field ID. I have looked through the docs, but they are light on highlighting typical uses (perhaps an example for each api element that shows how it works and why it exists in relation to backend data to frontend display, similar to the PHP manual. Something perhaps I can help with at a later date). I also think this is a type of issue can be a deal-breaker for new users because of the logic gap ($page->title outputs field content, $page->blocks outputs what might be field ID), and us newcomers can be an impatient group! So I hope solutions here will be a useful addition to the docs. After I learn how to deal with this, I'll add any info that might be useful for newcomers.
  14. I've been experimenting with field type Page, to add a page within a page (to replicate a block like system). I encountered some issues rendering the results, and while debugging and displaying the $page->fieldtypePage object I realised it was huge. I mean 1 minute to display huge. Even though in normal operation, printing out the whole object wouldn't be necessary. However I presume having an object that large must affect site performance. I won't be using this field type Page any more because I'm a bit of a fanatic for clean code and good performance. But in general, what do you think? Should this be submitted as a bug? If so, what's the correct procedure for that?
  15. I'm interested to know a good approach to grouping pages, where one page may be in two different groups (but re-using the same page for easy client editing). To clarify for those familiar with Drupal, there I would probably use Taxonomies, Blocks and Context modules. A taxonomy term for each group would be attached to pages (nodes), much like product categories would be, and menus and links would use Taxonomies (the Context and Blocks for displaying different elements on page depending on which group was accessed, but I don't need this part now) . Example organisation as follows (this is not PW Tree): Home - Courses - - Course One - - Course Two - - Course Three - - Course Four - Adult Courses - - Course One - - Course Two - Junior Courses - - Course Two - - Course Three - - Course Four - Summer Courses - - Courses Three - Special Courses - - Course Four (The PW Tree would need to be with only one occurrence of each Course page) I'm keen on the cleanest solution, ideally not adding modules, and a PHP solution no problem (though if it can be within PW as-is, great)
  16. I enabled language support and now I get "Trying to get property of non-object" for lines like: <p><?= $page->text ?></p> The content is still available in the backend. On another page I get text from the frontpage with: <?php $somepage = $pages->get(1); ?> ... <p><?= $somepage->text ?></p> This outputs the text although on the frontpage it doesn't. I also do this on the header. On the frontpage I added some fields that are thus "shared" among all pages the content fails with the error for `<?= $page->text ?>` but not for `<?= $pages->get(1)->text ?>`. On a third page everything works as expected All three pages have different templates. Additionally if the field is wrapped with frontend editing like so: <p><edit text><?= $page->text ?></edit></p> The page source will end up like this: <p></edit></p> Before having to dig deep into this: Any idea what it could be? I var_dumped $page and that gives an object.
  17. I cannot manage to delete this page upon uninstallation of a Process module I have that was working previously. I thought the only difference would be that I added `namespace ProcessWire;` to the start of the module PHP, however I've tried without it and still I get It is an admin page. Right now I have $get = 'template=admin, parent!=trash, name=importall, include=all'; $gp = wire('pages')->get($get); if($gp->id) { wire('log')->save($log, "$gp->id".get_class($gp).__NAMESPACE__); $gp->delete(); if(!wire('pages')->get($get)->id) wire('log')->save($log, "Deleted Imports page."); } previously $gp = $this->pages->get('template=admin, parent!=trash, name=importall'); if($gp->id) { $this->pages->delete($gp, true); $this->log->save($log, "Uninstalled ". get_class()); } Why will it no longer delete? I can't even do so by the GUI.
  18. For some reason when I unpublish an already-published page, even of a template other than the specified 'importer', all its fields are cleared on page render. How do I understand and remedy this? Peace & thanks public function init() { $this->addHookAfter('Page::render', $this, 'renderEditor'); } protected function renderEditor(HookEvent $event) { $here = $event->object; $page = $this->pages->get($this->input->get->id); //$this->log->message($page->template.$here->process); return; if ($here->process != 'ProcessPageEdit' && $page->template != 'importer') return; $css = $this->config->urls->ProcessImportAll . 'ass/ProcessPageEdit_importer.css'; $event->return = str_replace("</head>", "<link rel='stylesheet' type='text/css' href='{$css}'/>\n</head>", $event->return); $field = wire('fields')->get('name=pi_template'); if (count($field->templateTypes)>0) { $templates = $field->templateTypes; } else { $templates = []; foreach (wire('templates') as $tpl) $templates[] = $tpl->id; } sort($templates); //$tplTypes = json_encode($templates); $templatesFields = $this->getTemplatesFields($templates); $templatesFields = json_encode($templatesFields); $js = <<<EOT <script> $(document).ready(function(){ if (!document.getElementById('Inputfield_status_2048').checked) { $('#ProcessPageEditContent *').prop('disabled',true); } else { var all = $templatesFields; var sel = '#Inputfield_pi_template option[selected="selected"]'; var tpl = getTpl(); var arr = all[tpl]; var def = '<option value=""></option>'; $('#Inputfield_pi_match').prepend(def); filterFields(tpl); $('#wrap_Inputfield_pi_template .asmListItem .asmListItemRemove').click(clearFieldOptions); $('#Inputfield_pi_template').change(function() { var on = $(this).find('option[selected="selected"]')[0]; if (on !== undefined) { tpl = on.value; //console.log('clicked ' + tpl); filterFields(tpl); } else { tpl = null; clearFieldOptions(); } }); function filterFields(t) { if (t != null) { $('#Inputfield_pi_match').prop('disabled',false); arr = all[t]; //console.log(arr); $('#Inputfield_pi_match option').each(templateFieldOptions); $('#wrap_Inputfield_pi_fieldmap select option').each(templateFieldOptions); $('#_Inputfield_pi_maptab').click(function() { //$('#wrap_Inputfield_iu_fieldmap select option').each(templateFieldOptions); }); } else { clearFieldOptions(); } } function getTpl() { if ($(sel).length>0 && $(sel)[0].value) { var tpl = $(sel)[0].value; } else { var tpl = null; } return tpl; } function templateFieldOptions() { var val = parseInt(this.value); if (!arr.includes(val) && val>0) { //console.log(val + ' ' + arr); $(this).prop('selected',false); $(this).prop('disabled',true); } else { if (arr.includes(val) && val>0) { //console.log(tpl); $(this).prop('disabled',false); } } } function clearFieldOptions() { $('#Inputfield_pi_match').find('option[value=""]').first().prop('selected',true); $('#Inputfield_pi_match').find('option[value!=""]').each(function() { $(this).prop('disabled',true); }); $('#Inputfield_pi_match').prop('disabled',true); $('#wrap_Inputfield_pi_fieldmap select').find('option[value=""]').first().prop('selected',true); $('#wrap_Inputfield_pi_fieldmap select').find('option[value!=""]').each(function() { $(this).prop('disabled',true); }); $('#wrap_Inputfield_pi_fieldmap select').prop('disabled',true); } } }); </script> EOT; $event->return = str_replace("</body>", "$js</body>", $event->return); //$this->filterFieldFields($event); }
  19. Hi all, I'm still new to processwire and now I have to create the first hook. I need to modify the page-clone module, so there is a field in pages that has to be empty after cloning the page. How could I start this task?
  20. Hello, On my website I want to import categories from another website based on prestashop. For each categorie a new child page will be created, but if I want to import the categories again because there were some changes made in the categories in Prestashop, then the page has to be updated and not create a new page. So I tried the following: $parent = $this->session->Parent; foreach($categories as $item) { //make sure end of string ends with alphanumeric $str_catlink = $item['link_rewrite']; $category_name = preg_replace('/[^a-z0-9]+\Z/i', '', $str_catlink); // see if we already have this item $page = $parent->child("name=($category_name)"); // if we don't have this item already then create it if(!$page->id) { $page = new Page(); //etc etc etc But if I want to import the same categories now, there is an error: Call to a member function child() on a non-object. How can this be solved? Does anyone have an idea?
  21. Hi Guys, something I'm wondering about: is there any easy solution to show the template (or template label) within the page tree in the backend. The reason I'm asking is because we have a page tree consisting of many different pages and templates on the same level. For editors it would be nice to be able to see what template each page has without having to navigate into the page... Cheers, Kurbel
  22. Hello Fellow PW fans. I have since i started using PW allways been a bit afraid to use the API:s more advanced functions. Like creating pages or subpages on the fly in my PHP code in the page template file. So i read alot and finaly got a Eureka the other day. And have now tinkered around a bit and this simple example is the result. It´s just the bare basics. You could make this more advanced in infinity. I wanted to put this example somewhere for the future because i don´t think there is such a clean to the point example anywhere on the forums. All the others are deep within discussion threads with advanced stuff that are not of concern for people who looking for a simple example to start from. Notes: You should log in as admin before trying to run this code in your page template. I put the parent page i use in my testing as unpuplished for security. As allways, the API reference: https://processwire.com/api/ref/ is allways great to have when tinkering with the API. Any ways, here it comes, and you have to change paths and such to your requirements. <?PHP /* some random strings and stuff for testing */ $randTitle = 'test_' . mt_rand(0, 1000000); $randHash = 'test_' . md5(mt_rand(0, 100000) + time()); /* Example: Creating a new sub page to a parent page via API Author: EyeDentify This example do not check if the page name allready exist it just tries to save it no mather what. so you have to create that check your self. */ /* get parent page object to add sub page object to */ $addParent = $pages->get('/api-test-start/'); /* Instantiate a new page object */ $newPage = new Page(); /* turn output formating of for property manipulation */ $newPage->of(false); /* set the page objects parent so it is saved in the right place */ $newPage->parent = $addParent; /* set the name of the template to be used wich we uploaded before hand. */ $newPage->template = 'tmp_api_test_post'; /* sanitize and set page name and also used in the path */ $newPage->setName($sanitizer->pageNameUTF8($randTitle)); /* the title */ $newPage->title = $sanitizer->text($randTitle); /* set custom fields propertys, the ones we created ourselfs */ $newPage->api_test_hash = $randHash; /* save the page object to database as child of the given parent */ $newPage->save(); /* turn on output formatting again, importent because it should be ON when outputting it in template files later on. */ $newPage->of(true); ?> This is kind of a example and code template in one. I hope this can get others started that are beginners like myself to get more advanced with the PW API. I expect there is propably things that should be done a certain way but this is my way. Good luck with your API adventures. Update created a gist for the github users of the PW community of this example. https://gist.github.com/magnusbonnevier/4dbb3a28634a9b76bbf5855dd871606f
  23. I have a page that are either ) showing an automatic list of all pages with a certain template, if no pages are selected in a page field. 2) Or showing the selected pages from the page field. if ($page->custom_menu->count == '0') { $subjects = $pages->find("template=subject-page, sort=title"); } else { $subjects = $page->custom_menu; } When I set these "subject-page"-pages to hidden. The first option excludes these from the list as they should. But the second manually selected list will still show hidden pages. I have checked that these are actually hidden, with the following code: if ($subject->status & Page::statusHidden) { echo "I'm hidden!"; } else { echo "And I'm visible!"; } If I am not wrong, hidden pages have been removed from page fields by themself before, because of their status. But I'm not sure. I haven't used include=hidden. I am on ProcessWire 3.0.32, the page field is using PageListSelectMultiple*+.
  24. Hey, I was wondering if there's a way to add more fields to specify when creating a new page. At the moment, the only two fields are required for creating a new page. Title Name (Automated) I've configured processwire so that the chosen page to create is limited to one template. Guess this would make the process to achieve the above a bit easier. Regards,
  25. Hi Still on my quest to build my website. Since now I know how to basically display fields, I'm now at a design' step. I know I can do, what, and how, I want using PW, but there is so many possibilities! Could you help to choose the more efficient technique and/or point me pro and cons of each of them? My page is a classic team page Team Some text Director 1 (photo+text) Director 2 (photo+text) Other members ~35 photos separated in differents categories (photo, name and position title) Some text Method 1 : a page for each section. Pictures uploaded in one field, as described here. Using photo tags to create the different sections and description for name and position. Method 2: each person is a page. A field "category" will be added to displayed them correctly. Method 3 : repeater but I'm not sure yet how it works and his advantage or inconvenient. I have 35 photos to upload for now (one time upload, after I will add/modify only 2-3 by year). I was thinking using a module to batch Import via CSV to create pages (which seems to speed up with method 2) (However, I don't know if it's working for images). On the other hand, method 1 is also easy for uploading pictures in 1 click. However, adding description in batch seems more complicated and less easy to maintain (more clicks to see them). Also, subsidary question. If I want to re-use some pictures in an other webpage, is it easier to reuse from this page or just reupload and recreate a child page in an other page? Do I miss something? Thanks Melanie
×
×
  • Create New...