Page 1 of 1
N00b question: Is there a way to insert content from one page into another?
Posted: Sat Jan 28, 2006 5:04 pm
by thetallguy
I'd like to insert the title and abstract text from one page into another page. While I could probably use the News module to do it, that so far doesn't seem to do what I need. (Though I'm still researching it -- there's depth to that module, there is!
If News doesn't end up doing what I need, I'd need a tag that inserts the title and various content blocks from another page into the current page. Is there such a tag/module available?
Thanks!
Michael
PS: I'm trying to finish a web site this weekend... I'm looking for two solutions to every problem so I don't have to spend as much time researching things.
Re: N00b question: Is there a way to insert content from one page into another?
Posted: Sat Jan 28, 2006 6:08 pm
by cyberman
Have you already tried ContentAlias module ?
Re: N00b question: Is there a way to insert content from one page into another?
Posted: Sat Jan 28, 2006 7:57 pm
by thetallguy
Hmm... Can one insert content_alias into a template? If so, that would be close. I'd also need to get the page's title somehow.
Thanks for the help!
Michael
Re: N00b question: Is there a way to insert content from one page into another?
Posted: Sat Jan 28, 2006 10:20 pm
by Ted
Make a user-defined tag. Call it other_content. In it, put the code:
Code: Select all
echo $smarty->fetch('content:content_en', '', $params['content_id']);
Then you should be able to use {other_content content_id='5'} or whatever the proper id is.
Keep in mind that it's not tested, but it's very similar to how the {content} tag works.
Re: N00b question: Is there a way to insert content from one page into another?
Posted: Sat Jan 28, 2006 10:33 pm
by thetallguy
Hey, that looks easy. Thanks, wishy! Is there a way to grab the title and/or specially named content blocks? Where can I look in the code to figure out further questions myself? (Though I really appreciate the quick response.)
Michael
Re: N00b question: Is there a way to insert content from one page into another?
Posted: Sat Jan 28, 2006 10:36 pm
by Ted
Well, the title is a little more complicated. That is grabbed and put into memory for the specific page that you're on.
That would require hitting the database directly. When 0.12 comes out, it'll be a little easier with the content manager additions to the code base.
Re: N00b question: Is there a way to insert content from one page into another?
Posted: Sun Jan 29, 2006 12:27 am
by thetallguy
Erk. When that line of code executes, it causes PHP to exit with an error. But when I change it to use "content:Extra" (a block name) instead of "content:content_en", then it doesn't exit even though it also doesn't return the block data.
However, this appears to be exactly what {content} does, so why it would work one way and not the other is a mystery. Well, to me, anyway.
Thanks for your help!
Michael
Re: N00b question: Is there a way to insert content from one page into another?
Posted: Sun Jan 29, 2006 3:47 am
by Ted
What's the error?
Re: N00b question: Is there a way to insert content from one page into another?
Posted: Sun Jan 29, 2006 3:50 am
by thetallguy
This is from the Apache log:
Code: Select all
[Sat Jan 28 16:18:39 2006] [notice] Parent: child process exited with status 3221225477 -- Restarting.
[Sat Jan 28 16:18:40 2006] [notice] Apache/2.0.55 (Win32) DAV/2 PHP/4.3.11 configured -- resuming normal operations
[Sat Jan 28 16:18:40 2006] [notice] Server built: Oct 28 2005 02:08:11
[Sat Jan 28 16:18:40 2006] [notice] Parent: Created child process 2228
[Sat Jan 28 16:18:40 2006] [notice] Child 2228: Child process is running
[Sat Jan 28 16:18:40 2006] [notice] Child 2228: Acquired the start mutex.
[Sat Jan 28 16:18:40 2006] [notice] Child 2228: Starting 250 worker threads.
From the browser, it says "The connection has been reset."
Michael
Re: N00b question: Is there a way to insert content from one page into another?
Posted: Wed Feb 01, 2006 7:13 pm
by thetallguy
Wishy: Oh well, it looks like you're idea won't work. As far as I can tell (by reading code and by actually doing it), the code within the "content" handler (in content.functions.php) uses the ID of the current page when actually loading the content block. In fact, the page Id isn't even given to the content handler; the handler pulls it from the global page info. (At least in the latest stable release, and from my cursory reading, the latest SVN, too.)
In short, you can specify whatever ID you want, but it loads the content block from the current page no matter what.
The reason I'm going to this trouble is I want certain pages to have an "abstract" field. On a master page, I want to generate a list of children pages along with their abstract info. It's similar to what News does, except that these aren't news, they're permanent pages. (If I use News, then half my site content is in news, alongside real news, and the other half is in pages. This seems so confusing for editors.) If there was a way to extract another page's content blocks, this is trivial to do.
Is there another way to achieve this? I thought I'd found the simplest, most logical way to do this, but I'm a n00b, so I'm probably missing something obvious!
Thanks for your help, wishy!
Michael
Re: N00b question: Is there a way to insert content from one page into another?
Posted: Wed Feb 01, 2006 9:42 pm
by thetallguy
Thanks for your answer, Patricia! Yes, that would work, *except* that these blocks aren't global. They're individual to certain pages. For example, let's say pages A and B have two blocks, the standard content block and a custom block called "Abstract". ("{content block="Abstract"}") On a summary page, I wish to do something like this:
Code: Select all
Blah blah blah. You can find more information in the following pages:
{articlereference page="A"}
{articlereference page="B"}
where "articlereference" is a user defined tag that prints the title of the target page, and also the contents of the page's "Abstract" block. The tag is essentially an elaborate hyperlink to a fixed page.
Getting the title of another page is easy, of course. But grabbing content blocks turns out to not be so easy...
An alternate solution is to use the News module, but that would mean that I have both news and fixed pages within News. And it would mean that about a third of my site pages would actually be in News, while the rest would be regular pages, with the only distinction between the two being whether the page is referenced by another page or not. This seems like a confusing, error-prone hack to me...
Anyway, I'm realizing that I'm only looking at this problem from one direction. It's entirely possible that there are other ways of doing this that would be clean and simple.
Thanks again for your help!
Michael
Coding advice needed...
Posted: Fri Feb 03, 2006 6:28 pm
by thetallguy
I keep finding myself wanting this feature -- the ability to load a content block from one page into another. I'm thinking there's a solution here, but it touches on caching, which I'm afraid to screw up.
So, here's my idea: Modify content_get_template (in content.functions.php) so that it can take an optional alias/id in the template string. (E.g. "content:Abstract;newspage", where "newspage" is the alias of the page containing the Abstract block.) This change seems relatively straightforward; I'll use the current code if no alias supplied, or slightly different code (ContentManager::LoadContentFromAlias) if one is supplied.
My question is about content_get_timestamp. It looks like the production code inadvertantly never caches the content block; this appears to be fixed in SVN. (I'm obviously a total N00b with the code, so please correct me if I'm wrong.) For the rare occasions where someone would be pulling content from another page, is it acceptable to not call LoadPageInfoByContentAlias, thus saving us a database hit, and just return the current time?
Or is caching more important than I'm guessing?
Thanks!
Michael
PS: Thanks, Patricia, for pointing me to SVN. I really like the way you've made the latest code accessable to all of us -- it's so easy to check what's been fixed. What a great system!
Re: N00b question: Is there a way to insert content from one page into another?
Posted: Sun Feb 05, 2006 4:55 am
by Ted
Caching is pretty important.
With 0.12, you have a much better system. The hierarchy manager handles caching MUCH more easily. Take a look at how content is grabbed now...
Code: Select all
$manager =& $gCms->GetHierarchyManager();
$node =& $manager->sureGetNodeByAlias($somealias);
if ($node != null)
{
$contentobj =& $node->GetContent();
$title = $node->Title();
$content = $node->Show('content_en');
etc...
The nice thing is that if the page was called from somewhere else, it won't take the extra database hit. And if it does, it's just getting the content props (because the main object sans props is cached).
Does this help your cause at all?
Re: N00b question: Is there a way to insert content from one page into another?
Posted: Sun Feb 05, 2006 6:47 am
by thetallguy
wishy wrote:
Does this help your cause at all?
Why yes, I do believe it does.

I'm just finishing off the current site. Perhaps once the dust settles, I can play with the Beta. I can use it for the next site rev, if the beta turns golden fast enough...
Thanks for the code sample! I tell you, I'm having great time working with this CMS!
ME