Jul 04, 2009, 05:04 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Search via SMF or Google: modx forums all of modxcms.com web
  MODxCMS.com   Forums   Help Login Register  
News:Donate to MODx: Donations
Pages: [1] 2   Go Down
  Print  
Author Topic: Content of one page into another page by page ID  (Read 2215 times)
0 Members and 1 Guest are viewing this topic.
PhycoFalcon
Jr. Member
*
Posts: 7



« on: Jun 25, 2008, 11:21 PM »

I just want to retrieve the content of another page (by id) into the main page by putting into the main page's template the page id of the other page.
Something like this:
[*content&id=`12`*]

TIA! Smiley
Logged
sottwell
Documentation Team
*
Posts: 8,830



WWW
« Reply #1 on: Jun 25, 2008, 11:25 PM »

You can use a TV with the @DOCUMENT binding. I don't believe that any MODx tags in the document's content will be processed, however.

http://modxcms.com/document-binding.html
Logged

sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html
PhycoFalcon
Jr. Member
*
Posts: 7



« Reply #2 on: Jun 25, 2008, 11:31 PM »

Yeah, I looked into that too, but I don't know how to set up the template variable's input to accept a parameter from the template.
So, I put @DOCUMENT in "Input option values", with a type like 'textarea', then call it in the template by doing this:
[*ContentBlock?id=`12`*]
Why doesn't this work ? Undecided
Logged
sottwell
Documentation Team
*
Posts: 8,830



WWW
« Reply #3 on: Jun 25, 2008, 11:34 PM »

Ah, sorry, I didn't notice that you wanted the ID to be variable.
Logged

sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html
PhycoFalcon
Jr. Member
*
Posts: 7



« Reply #4 on: Jun 25, 2008, 11:41 PM »

It's okay. Would it work if I set the TV input field like this? id==@DOCUMENT
...am I on the right track? :-/
Logged
sottwell
Documentation Team
*
Posts: 8,830



WWW
« Reply #5 on: Jun 25, 2008, 11:44 PM »

I don't think so.

How about the GetField snippet? A snippet call I know can accept variables for its parameter values.

http://modxcms.com/getField-667.html
Logged

sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html
PhycoFalcon
Jr. Member
*
Posts: 7



« Reply #6 on: Jun 26, 2008, 12:55 AM »

Egh, I looked at the documentation, but that method seems to be too involved for what I want to do.
I just want to call content of a page into another page so that I can have different blocks of content on the frontpage; not all sites are linear, one page == one area of content.
I've heard stuff about Chunks, but they're not WYSIWYG formatted, and in a non-obvious portion of the site (not in the hierarchy)... Would be harder for my client to change.
It really shouldn't be this hard... Sad
Logged
TobyL
Coding Team
*
Posts: 1,004



« Reply #7 on: Jun 26, 2008, 04:10 AM »

Try this:


Create a TV with these properties:
Variable name: includeDocs
Input Type: "DropDown List Menu" or a "Listbox"
Input Option Values:
Code:
@SELECT pagetitle,id FROM {prefix_}site_content WHERE parent={page_id} ORDER BY menuindex
where {prefix} is your modx table prefix and {page_id} is the parent container of the documents you want to be able to include. youll need to replace this yourself.(If you don't have a parent container adjust the SQL accordingly)
Default Value: @INHERIT
Assign it to the template of your choice.

Now create a new snippet (name it "includeDocument" for instance) and paste the following code:

Code:
<?php

$output 
'';
/** A simple template to wrap around the included content
* Adjust as necessary... Classes are arbitrary - up to you*/

$includeTemplate = <<<EOD
<div class="includedDocument">
<div class="xHead"><h3>[+includedTitle+]</h3></div>
<div class="includedBody">
[+includedBody+]
</div>
</div>

EOD;

$docIds $modx->getTemplateVarOutput(array('includeDocs'),$modx->documentIdentifier);

if( 
count($docIds)>&& !empty($docIds['includeDocs']) ){
$includeDocs $modx->getDocuments(explode(',',$docIds['includeDocs']), 00"id,longtitle,content");

foreach ($includeDocs as $doc){
$item str_replace('[+includedTitle+]',$doc['longtitle'],$blockTemplate);
$item str_replace('[+includedBody+]',$doc['content'],$item);
$output .= $item;
}
}
return 
$output;

?>


Last thing to do is to place a snippet call in your document template [[includeDocument]]

This will give you a list of documents to choose from when you edit a page in the manager. And the snippet will fetch the document content based on the choice you made in the TV.

Hope this is more or less what you are trying to achieve...
« Last Edit: Dec 30, 2008, 08:44 AM by TobyL » Logged

PhycoFalcon
Jr. Member
*
Posts: 7



« Reply #8 on: Jun 26, 2008, 05:56 AM »

Hi, TobyL! Thanks for your time!

That's ... almost what I need. However, your code inspired me to write my own, so here's my version:

Code:
<?php
$output 
'';
/*
This is a simple snippet for replacing placeholders with docIDs in them with the content of the docID's corresponding page.
Example placeholder:
[+12+]
*/

$includeTemplate = <<<EOD
<div class="includedDocument">
<div class="includedBody">
[+includedBody+]
</div>
</div>
EOD;

// Set to your docIDs!
$docIDs = array(12,16,17);

for(
$i=0$i count($docIDs); $i++) {
$doc $modx->getPageInfo($docIDs[$i],1,'content');

$item str_replace('[+includedTitle+]',$doc['longtitle'],$includeTemplate);
$item str_replace('[+includedBody+]',$doc['content'],$item);
$output .= $item;

$modx->setPlaceholder($docIDs[$i], $output);
$output '';
}
?>

Obviously, my pageIDs are hard-coded. It wouldn't be too much effort to make a comma-delimited text field TV for that, however, me being a lazy programmer, I'm just going to leave it there for now. Not bad for my first MODx program! Smiley

Thanks for all the help getting here, guys!
« Last Edit: Jun 26, 2008, 05:59 AM by PhycoFalcon » Logged
cfn
Full Member
***
Posts: 134


WWW
« Reply #9 on: Oct 13, 2008, 07:33 PM »

@PsychoFalcon: Cool idea and I'm thinking about using it as a workaround to a problem I discovered.
@TobyL:  I really think your flexible TV is a great concept too, I can see where that would be very useful if a client needed to change content seasonally (a "the ski lodge is closed for the season" page, or a restaurant's summer menu).


I'm having a problem with @DOCUMENT so I found this thread and I think you have a solution.  Here is the problem I was experiencing:  http://modxcms.com/forums/index.php/topic,28663.msg180534.html#msg180534


But here are a few questions about your snippet, I'm pretty new to snippets so I appreciate your help:


1.)  You named it "includeDocument" or something similar?  The name doesn't matter?

2.)  From what I can tell [+12+] will call the document content, if and only if "12" is also hardcoded in the snippet under $docIDs = array.  Am I correct about that?

3.)  How would I change the code so that [+12+] will not do this but instead I would prefer to use something like [+CallDoc12+] just so I don't get confused and so this doesn't happen to interfere with Ditto or any other snippets or Modx functions?

4.)  When entering and saving this as a new snippet do any boxes need to be ticked on the snippet page?


Thanks!

John



Logged
Terry
Sr. Member
****
Posts: 321



WWW
« Reply #10 on: Dec 24, 2008, 02:01 PM »

TobyL

You snippet above is EXACTLY what I need for a project right now!  But I can't get it to display the contents of the documents I've selected.

My TV contains this:
Code:
@SELECT pagetitle,id FROM terrybar_site_content WHERE parent=49 ORDER BY menuindex

I've assigned the TV to the template I'm using and I"ve put the snippet call in the document where I'd like the specified content to appear.

When editing the document with this template, the TV provides the correct list of documents in parent folder 49 as expected.  I select the document I want and save.

However, there is no content output to my page.

Can you help me sort this out?

Terry
Logged

TobyL
Coding Team
*
Posts: 1,004



« Reply #11 on: Dec 24, 2008, 04:49 PM »

So sorry,... I'm closed for Christmas. In fact I'm heading out the door right now to a place without cables and without wireless.  I'll revisit when I'm back in 2 or 3 days.

Merry Christmas Smiley
Logged

Terry
Sr. Member
****
Posts: 321



WWW
« Reply #12 on: Dec 26, 2008, 12:53 PM »

Thanks TobyL.

Have a great holiday.

Terry
Logged

TobyL
Coding Team
*
Posts: 1,004



« Reply #13 on: Dec 27, 2008, 06:33 AM »

It seems I made a typo in the original snippet I posted above... I declared $includeTemplate at the top but used $blockTemplate later on in the code...

Try this instead:
Code:
<?php

$output 
'';
/** A simple template to wrap around the included content
* Adjust as necessary... Classes are arbitrary - up to you*/

$includeTemplate = <<<EOD
      <div class="includedDocument">
         <div class="xHead"><h3>[+includedTitle+]</h3></div>
         <div class="includedBody">
            [+includedBody+]
         </div>
      </div>
      
EOD;

$docIds $modx->getTemplateVarOutput(array('includeDocs'),$modx->documentIdentifier);

if( 
count($docIds)>&& !empty($docIds['includeDocs']) ){
   
$includeDocs $modx->getDocuments(explode(',',$docIds['includeDocs']), 00"id,longtitle,content");

   foreach (
$includeDocs as $doc){
      
$item str_replace('[+includedTitle+]',$doc['longtitle'],$includeTemplate);
      
$item str_replace('[+includedBody+]',$doc['content'],$item);
      
$output .= $item;
   }
}
return 
$output;

?>


« Last Edit: Dec 30, 2008, 08:43 AM by TobyL » Logged

Terry
Sr. Member
****
Posts: 321



WWW
« Reply #14 on: Dec 27, 2008, 09:56 AM »

TobyL

Thank You for taking a look.  I used the new snippet code.  No change.

I've been testing this on my wamp server.  Since I still couldn't get it work with the new snippet, I thought perhaps I missed a step.  So started from scratch, this time on my server site.  No change.

I feel silly about this, it seems so straight forward. . .   Can I pm you access to my site for a closer look?

Terry

Logged

Pages: [1] 2   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP

Copyright © 2005-2008 MODxCMS, All rights reserved. Contact Us
Styles by ziworks.com

Powered by SMF | SMF © 2006-2008, Simple Machines LLC

Valid XHTML 1.0! Valid CSS!