Jump to content

Tutorial: A Quick guide to ProcessWire for those transitioning from MODX


kongondo

Recommended Posts

  • 1 month later...

Hi Kongondo.

Coming from modX revo, I'm testing pWire's file field type, so I added this to output a link to a PDF from a file field type:

if ($page->pdf_docs_insert){ 
  echo "<a href='{$page->pdf_docs_insert->url}$page->pdf_docs_insert' target='_blank'> $page->pdf_docs_insert</a>"; 
} else {
// ...
}

The link is working but I can't output the description from the file field  pdf_docs_insert  I get the name of the PDF file but not the description of it. I tried several ways, but it doesn't seem to work like the description for image field types. This doesn't work too ->$file->description

Thank you again for your help and patience.

Link to comment
Share on other sites

Hi nfil,
 
Don't know whether I've said welcome to PW or not. If not, welcome :).
 
Are you allowing multiple or single file uploads on that field? 
 
If single...

if ($page->pdf_docs_insert){ 

	$myfile = $page->pdf_docs_insert;
	echo "<a href='{$myfile->url}' target='_blank'>$myfile->description</a>"; 
}
	
else {
// ...

}

If multiple files, the field returns an array, hence you need to loop through it...

if ($page->pdf_docs_insert){ 

	$myfiles = $page->pdf_docs_insert;
	
	foreach ($myfiles as $myfile) {
		echo "<a href='{$myfile->url}' target='_blank'>$myfile->description</a>";
	}
}

else {
// ...please give me some files mate!
}

Check out the cheatsheet for more info

  • Like 3
Link to comment
Share on other sites

Thank you for your welcome Kongondo.

You helped before, I'am glad don't remember my newbie questions bothering pWire experts. Your awesome answer helped me a lot to correct and understand the correct pWire syntax. I hope some other pWire newbies can learn too from my mistakes.

Check out the cheatsheet for more info  Bookmarked!!

Link to comment
Share on other sites

Ha! Now I have another ten pages to read, along with those 30 designer depot etc. articles piled up in my inbox and a couple of issues of .Net gathering dust under the bed. I'm actually working on ClipperCMS, a fork of Evo, now, and it's while researching something that cropped up during a write-up of its API that I found your post. I suspect it's what I needed some time last year to help me make sense of PW, since my brain has been rewired to view the world from an Evo standpoint. And now I'll have to read it and have another look. Pretty much like MODX, in fact - my first reaction to that was: "Oh no, another CMS that keeps everything in the database" (after finding Joomla site after Joomla site like watching paint dry as the page built up from bits & pieces). Something spurred me to have another look at MODX later, and I latched on to it immediately second time around. I'm pretty committed to Clipper, I think it has a great future for Evo fans, but I'm sure it's worth having a go at PW as well, and your guide could well give me the boost I need to do that in a reasonable time.

TVM!

:P  KP

  • Like 3
Link to comment
Share on other sites

Ha! Now I have another ten pages to read, along with those 30 designer depot etc. articles piled up in my inbox and a couple of issues of .Net gathering dust under the bed. I'm actually working on ClipperCMS, a fork of Evo, now, and it's while researching something that cropped up during a write-up of its API that I found your post. I suspect it's what I needed some time last year to help me make sense of PW, since my brain has been rewired to view the world from an Evo standpoint. And now I'll have to read it and have another look. Pretty much like MODX, in fact - my first reaction to that was: "Oh no, another CMS that keeps everything in the database" (after finding Joomla site after Joomla site like watching paint dry as the page built up from bits & pieces). Something spurred me to have another look at MODX later, and I latched on to it immediately second time around. I'm pretty committed to Clipper, I think it has a great future for Evo fans, but I'm sure it's worth having a go at PW as well, and your guide could well give me the boost I need to do that in a reasonable time.

TVM!

:P  KP

OMG! Keith is here!!! :) Welcome to PW and the forums! Nice to see you in these parts. I didn't know you went with Clipper...anyway, hope to see you here more :):D

  • Like 1
Link to comment
Share on other sites

Hi kp52 and welcome. Nice to read from you here ;)

the boost I need to do that in a reasonable time.

check this out for more boost.

COMING FROM MODX ?

Link2: A MODX refugee: questions on features of ProcessWire
http://processwire.c...of-processwire/

Link3: Code comparison between modx and processwire.

http://processwire.c...ge-2#entry30349

PROCESSWIRE CMS INSIGHTS

Link1: Very good case study from RayDale giving good insight in processwire
http://processwire.c...a-a-case-study/

Link2: Symphony or Processwire ? Another good insight.

http://getsymphony.c...s/thread/79645/

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Find more boost in these useful collected posts here:

http://processwire.com/talk/topic/4173-grouped-forum-posts-links-articles-tutorials-code-snippets/

  • Like 2
Link to comment
Share on other sites

  • 1 month later...
echo "<ul>";
foreach ($page->children as $child) {
         echo "<li><a href='{$child->url}'>{$child->title}</a></li>";
}
echo "</ul>";

How do I take this and make it so that I can get pull the children of an unpublished page? The site I'm working on is for a fairly large fitness center that offers multiple program/classes. My structuture is something like this:

-Program Overview

-Program Classes (unpublished to act as a container)

-Class One

-Class Two

-Class Three

-Program Instructors (unpublished to act as a container)

-Instructor One

-Instructor Two

-Instructor Three

 

Any insight is always appreciated. I'm still ironing out issues with the transition from ModX.

 

Link to comment
Share on other sites

Oh, I understand now. Try this:

foreach ($page->children("include=all") as $child){
    foreach($child as $grandchild){
        echo $grandchild->title;
    }
}

However there are other ways that might be cleaner. Perhaps you could use a selector to find all those pages like this:

$grandchildren = $pages->find("template=template_name");

Or something along those lines, then foreach through $grandchildren

Or maybe:

$grandchildren = $pages->find("parent.template=template of the unpublished child pages"); 

So many options :)

  • Like 1
Link to comment
Share on other sites

bodhic,

Can you show us the selectors exactly as you tried them? and also recreate your page tree again, this time with the names of the templates for each page in brackets after the names of the pages.

In case you don't already know about it, you should install Nik's awesome Selector Test module:

http://mods.pw/2r

It will help you test your selectors in a very quick way.

Link to comment
Share on other sites

-Program Classes (unpublished to act as a container)

-Class One

-Class Two

-Class Three

-Program Instructors (unpublished to act as a container)

-Instructor One

-Instructor Two

-Instructor Three

 

 

I suppose you don't need "Programm Classes" to be ever displayed, right? Then give theses container pages no template file at all. The child pages get their own template ("class_and_instructor", to give it a name for example) then, and now you can use

$childpages = $pages->find('template=class_and_instructor');

foreach($childpages as $child) {
echo $child->title;
}
 
Link to comment
Share on other sites

  • 2 months later...

This is too blatant. 

In ModX I had a basic structure for my concept.

I knew what to do in the header chunk and the footer chunk the rest I've done in the content.

I figure it with Content and Template Variables. 

Im PW its much more complicated for me. its too flexible. you can do what you want and on every place. 

DAMN 

I have  really get used to it. :) 

  • Like 1
Link to comment
Share on other sites

  • 11 months later...

In MODX there's an Extra called GetResources which allows you to loop through Resources and display the contents via a mini template (TPL).

For the PW equivalent, I use the foreach loop combined with selectors. Simple enough.

Back to getResources, I had a great setup whereby I could loop through several resources and output the content through a different TPL (mini template) depending on a field value within a Resource. IE I'd end up with a single page but the content inside would have several different layouts such as

Block 1 = Image on left. Text on right.

Blcok 2 = Image on right. Text on left.

Block 3 = Text on top. Image underneath.

Edit: There's a visual explanation here: http://www.sepiariver.ca/blog/modx-web/how-to-dynamic-content-blocks-with-modx-getresources/

Is this relatively simple with PHP and PW? I'm not looking for code samples but a more accurate idea of what to google. IE What's the proper terminology in PHP?

Link to comment
Share on other sites

@peter: take a look at InputFieldFile.

// usage with a Inputfield file with the name 'your_field':
$tpl = new TemplateFile($config->paths->templates . "includes/" . $page->your_field);
$tpl->set('current', $page);
$markup = $tpl->render(); 
You then can access al Page fields in the php file with $current, like $current->title or $current->id etc.
  • 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
×
×
  • Create New...