Sep 07, 2008, 02:06 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
modxcms.com web
  MODxCMS.com   Forums   Help Login Register  
News:Read what MODx Developers say: MODx Dev. Blogs
Pages: [1]   Go Down
  Print  
Author Topic: Content of one page into another page by page ID  (Read 576 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: 7,908



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: 7,908



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: 7,908



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: 742



« 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)>0 && !empty($docIds['includeDocs']) ){
$includeDocs = $modx->getDocuments(explode(',',$docIds['includeDocs']), 0, 0, "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...
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
Pages: [1]   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 1.1.4 | SMF © 2005, Simple Machines LLC

Valid XHTML 1.0! Valid CSS!