-
Posts
5,008 -
Joined
-
Days Won
333
Everything posted by Robin S
-
Hi @Roope, Love this module - it's used in all my sites. Is it possible to disable the module on some pages via a hook? I need to disable the obfuscation when a particular GET variable is present.
-
I want to reorder my Pageimages array so that portrait-format images are placed last. Currently I'm removing portrait-format images and then adding them back. $listing_images = $page->listing_images; foreach($listing_images as $listing_image) { /* @var Pageimage $listing_image */ if($listing_image->height() > $listing_image->width()) { $listing_images->remove($listing_image); $listing_images->add($listing_image); } } This works, but just wondering if there is some better WireArray method I could use that works like "move this item to the end of the array".
-
Rather than edit the DB for an existing field, you could make a simple fieldtype module that extends FieldtypeTextarea: <?php class FieldtypeLongTextarea extends FieldtypeTextarea { /** * Module information */ public static function getModuleInfo() { return array( 'title' => 'Long Textarea', 'version' => 1, 'summary' => 'Field that stores multiple lines of text in a MySQL LONGTEXT column type.', ); } /** * Get database schema used by the Field * * @param Field $field * @return array * */ public function getDatabaseSchema(Field $field) { $schema = parent::getDatabaseSchema($field); $schema['data'] = 'longtext NOT NULL'; $schema['keys']['data'] = 'FULLTEXT KEY data (data)'; return $schema; } }
-
Welcome @fabjeck, Having different markup for different templates is what the markup regions feature is all about. First, make sure you are up-to-speed with markup regions by reading the related blog posts: https://processwire.com/blog/posts/processwire-3.0.49-introduces-a-new-template-file-strategy/ https://processwire.com/blog/posts/processwire-3.0.50-core-updates/ https://processwire.com/blog/posts/processwire-3.0.62-and-more-on-markup-regions/ Regarding the #content markup in _main.php and your "normal" template file (let's say it is called "basic-page.php") there are two approaches - either is fine; it's just whatever you find easier to manage. Note that I am only showing a portion of _main.php below - this file needs to include complete HTML page markup: doctype, <head>, <body>, etc. Approach 1: put your normal #content markup in _main.php and leave basic-page.php empty of markup. _main.php <div id="content"> <!-- Your normal markup here --> <h1><?= $page->title ?></h1> <!-- etc --> </div> basic-page.php - no markup Approach 2: put an empty #content region in _main.php and put your normal markup in basic-page.php _main.php <div id="content"></div> basic-page.php <div id="content"> <!-- Your normal markup here --> <h1><?= $page->title ?></h1> <!-- etc --> </div> And in either approach, your home.php is the same: <div id="content"> <!-- Your home markup here --> <section> <div class="slider"> <!-- Find and output some news pages using a selector --> </div> </section> <section> <div class="news"> <!-- Find and output some news pages using a different selector --> </div> </section> </div>
-
Maybe a Javascript error - anything showing in your dev tools console?
-
Then they are not a company that deserves your money. Time to vote with your wallet and move to a new host.
-
Hi @adrian, everything is working as expected thanks - just took me a moment to connect the dots that no Tracy debug bar = no Tracy methods available (which makes sense). Great to have you back around here!
-
Welcome @obesegiraffe, Not sure that this could be the cause of the problem, but the way you are checking if the Options field is populated looks a bit unusual to me. Does it make a difference if you use count() instead? <?php if(count($page->percent_leased)){ ?> <h2><?=$page->percent_leased->title?>% Leased</h2> <?php } ?> The database table looks like what you get if your Options field is set to one of the "Multiple values" inputfields. If you have changed the input type from Multiple to Single at some point then you would need to save each of the pages in admin that had any multiple values saved for it in order to trigger the value to update.
- 2 replies
-
- 1
-
-
- select options
- options
-
(and 1 more)
Tagged with:
-
Welcome @Cabcom, Sure it is possible, but not a simple task. You'd be looking at something like the following: Create elements (divs or whatever) in the front-end that represent your repeater items (probably using repeater item page ID as an identifier). Use some Javascript on the elements that supports drag-and-drop sorting - I'm sure there are a number of off-the-shelf solutions for this. When a submit button is clicked, submit an array of the the repeater item IDs in the current sort order to a ProcessWire page (using a form or AJAX). In the template for that page, get the submitted array and apply the sorting to the repeater field using the API. It might be easier to remove all items from the field and then add the items back in the array order than to try and adjust the sorting of the items already in the field. If you are up for the challenge I'm sure you'll find help here in the forums if you get stuck on a step.
- 1 reply
-
- 2
-
-
"published" and "modified" always have the same value
Robin S replied to Marcel Stäheli's topic in API & Templates
I tested and cannot reproduce. For published pages, editing and saving a page updates the modified timestamp but not the published timestamp. But for news pages I think it is more typical to add a datetime field to the template to serve as the posting date, so the user can change the date to suit. For instance, to set a future posting date and then in your news selector you exclude pages with posting date greater than today. -
@tpr, there is an issue with the "edit field" helper link shown in Page Edit for fieldsets. Instead of linking to the the settings of the fieldset itself it links to the settings of the first child field of the fieldset.
-
Assigning Fields to Repeaters with the API
Robin S replied to thetuningspoon's topic in API & Templates
Probably a question best answered by Ryan in the pro support board, but this worked for me... // Name of repeater matrix field $matrix_field_name = 'test_matrix'; // Name of matrix type you want to add field to $matrix_type_name = 'type_1'; // Name of field you want to add to matrix type $add_field_name = 'images'; // Get field objects $matrix_field = $fields->get($matrix_field_name); $add_field = $fields->get($add_field_name); // Add field to repeater matrix fieldgroup $matrix_template = $templates->get("repeater_$matrix_field_name"); $matrix_fieldgroup = $matrix_template->fieldgroup; $matrix_fieldgroup->add($add_field); $matrix_fieldgroup->save(); // Associate field with matrix type $matrix_types = $matrix_field->type->getMatrixTypes($matrix_field); $matrix_type_integer = $matrix_types[$matrix_type_name]; $property = "matrix{$matrix_type_integer}_fields"; $field_ids_in_type = $matrix_field->$property; $field_ids_in_type[] = $add_field->id; $matrix_field->$property = $field_ids_in_type; $matrix_field->save(); -
See the "https" property of the Template class: https://processwire.com/api/ref/template/ $t = $templates->get("name=admin"); $t->https = 0; $t->save();
-
@rst, when you get 403 or 404 errors after submitting a form then it is usually mod_security that is to blame, as suggested above. You'll need to get it disabled one way or another. If you are on a cPanel host you can sometimes disable it there... ...otherwise you need to put in a support request to your host and ask for it to be disabled.
-
Hi @tpr, I've been working on a module that adds an icon to file items in a File field and checking to make sure it plays nicely with the "noFilenameTruncate" option in AOS. So I've been looking closely at the layout and have a suggestion for fine-tuning the noFilenameTruncate styles. Here is the default appearance of a File field, without AOS noFilenameTruncate activated: And here is the appearance when noFilenameTruncate is activated: And what I'd like to suggest is... Reduce the padding of the header to compensate for the extra line-height you added. The float:left you added to the file icon shifts it up a bit from the default, so compensate for that with a some extra top offset. Put the delete icon back over on the right by positioning it absolutely. It's better over there if you have several files to delete because you don't have to go hunting for it. The result... And the modified SCSS for that: html.noFilenameTruncate { p.InputfieldFileInfo.InputfieldItemHeader { padding: 6px 34px 6px 25px; position: relative; } i.fa-file-image-o, .InputfieldFileInfo i { left: -21px !important; top: 3px; float: left; } a.InputfieldFileName { line-height: 1.33; margin-left: -22px; word-wrap: break-word; } label.InputfieldFileDelete { position: absolute; top: 8px; right: 8px; } } What do you think?
-
$cc_recipient[0] is the first item in the array - if you dump that item, is it a valid email address? Also, you say WireMail but as far as I know there is no CC method in the WireMail base class. Maybe you are using some module that extends WireMail?
-
Custom PHP code to populate select option values in admin
Robin S replied to waheed's topic in API & Templates
@waheed, Repeater items are pages so what you want is a Page Reference field. Set the selectable pages to the value of the Repeater field (which is a PageArray). -
There are long-standing issues with the $user page having output formatting off by default - there are a number of forum topics where it has come up. I'm not sure if it's deliberate or if output formatting is off consistently for $user, but you could use $user->getFormatted('date') to be sure. Related topics:
-
Best approach to a long page/unique template with many different fields
Robin S replied to cjx2240's topic in Getting Started
@cjx2240, I made a new module... -
Page referencefield - custom PHP code not working in repeater
Robin S replied to gebeer's topic in API & Templates
See this issue: https://github.com/processwire/processwire-issues/issues/267 The example hook has been updated on the dev branch. $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'mypages') { $event->return = $event->pages->find('your selector here'); } });- 2 replies
-
- 2
-
-
- page reference
- custom php code
-
(and 1 more)
Tagged with:
-
Restrict Repeater Matrix Allows restrictions and limits to be placed on Repeater Matrix fields. Requires ProcessWire >= v3.0.0 and FieldtypeRepeaterMatrix >= v0.0.5. For any matrix type in a Repeater Matrix field you have the option to: Disable settings for items (cannot change matrix type) Prevent drag-sorting of items Prevent cloning of items Prevent toggling of the published state of items Prevent trashing of items Limit the number of items that may be added to the inputfield. When the limit is reached the "Add new" button for the matrix type will be removed and the matrix type will not be available for selection in the "Type" dropdown of other matrix items. Hide the clone button when the limit for a matrix type has been reached. Note that in PW >= 3.0.187 this also means that the copy/paste feature will become unavailable for the matrix type. Please note that restrictions and limits are applied with CSS/JS so should not be considered tamper-proof. Usage Install the Restrict Repeater Matrix module. For each matrix type created in the Repeater Matrix field settings, a "Restrictions" fieldset is added at the bottom of the matrix type settings: For newly added matrix types, the settings must be saved first in order for the Restrictions fieldset to appear. Set restrictions for each matrix type as needed. A limit of zero means that no items of that matrix type may be added to the inputfield. Setting restrictions via a hook Besides setting restrictions in the field settings, you can also apply or modify restrictions by hooking RestrictRepeaterMatrix::checkRestrictions. This allows for more focused restrictions, for example, applying restrictions depending on the template of the page being edited or depending on the role of the user. The checkRestrictions() method receives the following arguments: $field This Repeater Matrix field $inputfield This Repeater Matrix inputfield $matrix_types An array of matrix types for this field. Each key is the matrix type name and the value is the matrix type integer. $page The page that is open in ProcessPageEdit The method returns a multi-dimensional array of matrix types and restrictions for each of those types. An example of a returned array: Example hooks Prevent the matrix type "images_block" from being added to "my_matrix_field" in a page with the "basic-page" template: $wire->addHookAfter('RestrictRepeaterMatrix::checkRestrictions', function(HookEvent $event) { $field = $event->arguments('field'); $page = $event->arguments('page'); $type_restrictions = $event->return; if($field->name === 'my_matrix_field' && $page->template->name === 'basic-page') { $type_restrictions['images_block']['limit'] = 0; } $event->return = $type_restrictions; }); Prevent non-superusers from trashing any Repeater Matrix items in "my_matrix_field": $wire->addHookAfter('RestrictRepeaterMatrix::checkRestrictions', function(HookEvent $event) { $field = $event->arguments('field'); $type_restrictions = $event->return; if($field->name === 'my_matrix_field' && !$this->user->isSuperuser()) { foreach($type_restrictions as $key => $value) { $type_restrictions[$key]['notrash'] = true; } } $event->return = $type_restrictions; }); http://modules.processwire.com/modules/restrict-repeater-matrix/ https://github.com/Toutouwai/RestrictRepeaterMatrix
-
Choosing between Page Reference and Options field types
Robin S replied to Robin S's topic in General Support
@cstevensjr, wow, I did not know that unpublishing a page had the effect that the page and its children are hidden to site editors. Great tip! -
Choosing between Page Reference and Options field types
Robin S replied to Robin S's topic in General Support
Yeah, when I first started working with pages simply as options for a Page Reference field I thought that their presence in the page tree might be confusing for editors, but nobody has ever mentioned it so I don't worry about it now. Another thing that probably works but that I haven't tried is storing such pages under the Admin branch of the tree. Does anyone do this and does it work okay? -
Choosing between Page Reference and Options field types
Robin S replied to Robin S's topic in General Support
Thanks for the replies. I remembered a downside of the Options fieldtype and that is awkwardness of adding selectable options to the field via the API: I think I will stick with Page Reference fields for the most part. -
@Roych, if a second argument is given to date() it must be a timestamp. So you need the unformatted value of the date field: <?php if (date('d-m-Y') == date('d-m-Y', $single->getUnformatted('Start_date'))): ?> <div class='Danes-text'>TODAY!</div> <?php endif; ?>