Jump to content

PageTable - Pagefield - Special Template....headache


Recommended Posts

Hi guys,

maybe it's to late and i don't see the missing link....so i've to write down the problem...


PageTable field - downloads


templates for the PT field are:

doc   (contain fields like doc ->filefield, counter ->counterfield, description ->textfield, cat as a pagefield and filesize as string...)

docx      -"-

pdf        -"-

this fields are all single file fields! They follow soma's approach of flexible downloads with files as pages.

templates are build like this example code and so this pages works as url to the files:

 * doc.php

	$page->counter += 1;
	$page->save(array("quiet" => true));
	wireSendFile($page->doc->filename, $options);

this pagetable pages are all stored under /home/documents/....

so usually i render the templates from such pagetable fields without including _main.php and all is there and works like:

//render pagetable pt_inhalt
     foreach($page->pt_inhalt as $l){
         $content .= $l->render();

But with this downloads PageTable i can't render the templates since they only work for delivering the documents....

ok i've to render it different...

//render pagetable pt_download

    $content .= $page->pt_downloads;     
    //gives me the pages from the pagetable like 
    // the tree file downloads in the list 1054|1055|1061

    $content .= $downloads->find("doc_cat=1060");
    //gives me all files in the list with cat id = 1060 like 
    // the two in cat "Information" 1055|1061


So the question is how is the easiest way to render such a pagetable content as a table?

and challenge is how to separet the downloads/files to the categories...

- i know i've read in the forum a post about rendering pages/fields as a table but i didn't find it now to study?

- i know how to search for the right categories via find() like:

     //get all categories from the parent page
     $cats = $pages->get(1057)->children("include=all");

     //go trow all categories and search if a cat has a download
     foreach ($cats as $cat) {

          //find all $downloads with the doc_cat field)
          $found    = $downloads->find("doc_cat=$cat");

          //only output category if there is a download in the category
          if ($found != "") {

               //output the main cat nav as a tab interface

but i don't know how to additional get the whole stuff together for the needed output in this time.

Have it working with output all categories and all files but not only thoose who used in exact this pagetable content....since i need different places for filedownloads i choose this setup to have:

a) a easy editor interface for adding files with pagetable field

b) a central document root for all docments (would be important for further things)

From the example image above it should be on frontend like:

-> "Vorlagen"  as group/header

-> File one with title | desc | filesize | downloadlink | counter of downloads

->"Information" as group/header

-> File two with title | desc | filesize | downloadlink | counter of downloads

-> File tree with title | desc | filesize | downloadlink | counter of downloads

may someone have a hint for me to take the right direction.

Best regards mr-fan

Link to comment
Share on other sites

since i'm on dailyjob now just linking some notes/links for tonight....;)

didn't need  ->has() selector before...this may works to get only download/file pages as items that are in my pagetable pagearray...


and get the items on every cat may i have to setup this in a function to get items per cat


...maybe i found more on this in my luchtime

Link to comment
Share on other sites

hi mr-fan,

i'm sorry i think i don't fully get your problem... but 2 little things:

i don't understand your problem with outputting the pagetable items?!

//render pagetable pt_inhalt
     foreach($page->pt_inhalt as $l){
         $content .= $l->render();

what is pt_inhalt? what sould be the result of this? a list of all available downloads? why do you render each item? why not just echo the parts you want to be displayed?

foreach($pagetableitems as $item) {
   $content .= $item->title . " - " . $item->whatsoever . "<br>";
echo $content;
Link to comment
Share on other sites

Ok you've got me with the "h" ;)

the rendering did not work while the pagetable pages are not working as real pages - they work as a kind of file URL

example from the screenshot - item 2:

a pagetable template named doc.php with the code from above works like a file link if you type or link to the page

mysite/documents/testdoc.doc   == the page   -> the page counts the access and deliver the file under site/assets/

you could change the file from the file field but the URL and pagename would still work...this is SEO for files and i could counting access...

so render them like a other pagetable - in my example code i use this on a other pagetable fieled called pt_inhalte would not work.

i've to render them extra - and get the pagefields from the template (doc.php) for display the list like

title with link | sum of downloads | size of the file

The problem is - i have all pages that used by the pagetable - i could get all used categories - now i've to render a table with used cat and as rows the pagetable pages....under the right category.

Maybe i've "Tomaten auf den Augen"

But i've some ideas to try&test for tonight...so i think i can get it.

for the crosslinking - soma's flexible file downloads approach


Link to comment
Share on other sites

So here we are now it is working....just some nesting foreach on the right place and start the output from the pagefield with the categories was the right way to go here is my easy result of my example to get the downloads in the right order of the categories....

//render pagetable pt_download

     //set vars
     $out = "";
     $cat_content = "";
     $tab_content = "";
     $first_cat = 0;
     $first_tab = 0;

     //all pagetable pages
     $downloads = $page->pt_downloads;

     //get used cats in the pagetable field
     $cats = new PageArray();
     foreach ($downloads as $d) {

     //go trow all cats and search if a cat has a download
     foreach ($cats as $cat) {
          //check for first item and count up the $first var
          $active = ($first_cat == 0) ? " active" : "";
          //output cat_content
          $cat_content .= '<li class="'.$active.'"><a data-toggle="tab" href="#'.$cat->name.'">'.$cat->title.'</a></li>';

          //output tab_content start/header
          $tab_content .= '<div id="'.$cat->name.'" class="tab-pane '.$active.'"><hr class="vertical-space1">';

          //get items of a cat inside the tab_content
          $items = $downloads->find("doc_cat=$cat");
          foreach ($items as $i) {
               $tab_content .= '<h1>'.$i->title.' '.$i->filesize.'</h1>';
          //output tab_content end/footer
          $tab_content .= '</div>';

     //output cat navigation of all used cats in the pagetable field pt_downloads
     $content .= '<ul class="nav nav-tabs" id="myTab">';
          $content .= $cat_content;
     $content .= '</ul>';

     //output tab content with all items sorted to the right cat
     $content .= '<div class="tab-content" id="myTabContent">';
          $content .= $tab_content;
     $content .= '</div>';


this gives me a tabbed content with headings comes from the categories used in the pagetable - if files are chaning or a new category is added it should work as intended.

For shure the tab_content is only testing output this will be a sortable little table in a few minutes... ;)

May the code could be better i'm not that badass PHP guy.....but i leave it here to show my solution.... ;)

Thank you Bernhard for your time and the unnecessary and embarrassing "h" so your post helped me at least, too!

And to all others "don't code without enough sleep - it could be very dangerous... :excl:

Best regards mr-fana

added image...


Edited by mr-fan
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

  • Recently Browsing   0 members

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