Jump to content

dynamic/moveable fields


maxf5
 Share

Recommended Posts

The previous topic seems to be deleted. So is there any solution for dynamic / moveable fields in PW? (Besides the Pro Module: Repeater Matrix, PageTableExtended from @MadeMyDayis just for One-Page websites from what i saw ).
This would definatly bring it to a new level. I am thinking about grids, columns and a way to switch/drag positions of fields in a page.

If not, do you have any ideas to implement this feature? I would build a plugin if i have the time realise. 

Link to comment
Share on other sites

You can make content blocks with Page Table or Page Table Extended, to display on any page.

  1. Create a Page Table field.
  2. Create templates for each of your content blocks, assigning the necessary fields (PHP files not necessary for these).
  3. Configure your Page Table field to use those content block templates.
  4. Assign Page Table field to your front-end template (template.php).
  5. In template.php, iterate over the Page Table field, and use PHP switch() to display different HTML and field data based on the content block name.
  6. If you want to get fancy, configure Page Table Extended to display rendered HTML on the admin side (Display Output Options).
  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...

I was testing out that solution @evan

Works pretty well so far. I put the range slider to each template block to set the grid widths for desktop, tablet and mobilephones. Atm working on the output of the grids and cols.

There are a few question i have in mind.

1) My website has a search engine, so how you can search in those blocks?

I think you can just use field.subfield but not field.subfield.subsubfield as selector.

Like my PageTable field is called views. 

$selector = "title|views.accordion.textarea";

$results = $pages->find($selector);

2) PageTable extended would be kickass, but i am using blank templates without PHP Files. Rendering wont work as far as i read the docs.

Link to comment
Share on other sites

Your approach is slightly off – remember that the items in a Page Table field are actually pages.  There's a few different ways you could do this, but here's how I've done it in the past, assuming the content blocks are children of the page:

// Query normal pages
$query = $sanitizer->text($input->get->query);
$results = $pages->find('template!=content_block, title|body*="'.$query.'"');

// Query content blocks
$content_blocks_query = [
    'template=content_block', // Template
    'title|body*="'.$query.'"' // Fields
];

// Find parent pages of content blocks
$content_block_results = new PageArray();
foreach ($pages->find( implode(', ', $content_blocks) ) as $p) {
    $content_block_results->add($p->parent);
}

// Combine results
$results->import($content_block_results);

// Render $results

If you're talking about Page Table Extended's admin-side rendered HTML, it actually works independently of the normal templates.  Take a look at the PageTable Render Layout Options, you can specify CSS and template files there.

  • Like 2
Link to comment
Share on other sites

Hey @evan, thanks for your time and patience.

My content-blocks aren't stored as subpage on the particular page. I collect them in an unpublished page (called Views, due to menu reasons).

Is there a chance to search in the content of the blocks referring to the linked page?

This will of course return the one unpublished page where all blocks are stored (Views)
 

<?php
$q = $sanitizer->text($input->get->q);

$input->whitelist('q', $q);
$q = $sanitizer->selectorValue($q);

//selector normal content
$selector = "title|headline|summary~=$q, limit=50";

// selector content blocks
$views_query = [
  'template=Text|ParallaxBanner', // Template
  'textfield|parallaxtext*="'.$q.'"' // Fields
];

if($user->isLoggedin()) $selector .= ", has_parent!=2";

// normal pages
$matches = $pages->find($selector);

// Find parent pages of content blocks
$views_results = new PageArray();
foreach ($pages->find( implode(', ', $views_query) ) as $p) {
  $views_results->add($p->parent);
}

// Combine results
$matches->import($views_results);
?>

 

Link to comment
Share on other sites

Yep, you can.  Again, Page Table fields return a normal PageArray, so you can manipulate them as such.  You'd need to iterate over the Page Table field on the pages that have that field, i.e.:

$query = "My string";
$results = $pages->find('template=page_with_content_block');

$content_block_results = new PageArray();
foreach ($page_results as $p) { // Find pages with content block field
	if ($p->page_table_test->find('body*="'.$query.'"')->count() > 0) { // Check if content blocks contain query
		$content_block_results->add($p); // Add to results
	} else continue;
}

// Render $content_block_results or combine with other results

 

  • Like 2
Link to comment
Share on other sites

Holy shit, it works! thank you so much.
And sorry for the long questions, i shoud have learned other template strategys earlier.

I will share my codes when its all finished for people who are interested. I built some kind of page/grid-builder with uikit and PageTables.

Will now look at Page Table Extended.

  • Like 2
Link to comment
Share on other sites

3 hours ago, maxf5 said:

I will share my codes when its all finished for people who are interested. I built some kind of page/grid-builder with uikit and PageTables.

Would be great to see a working example. An exported site profile maybe? Thanks advance!

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...