Custom assets


(Geoffrey Bailey) #1

Hi,


I’m working on a custom asset type that needs to include other pages within it. The asset reads in a bunch of asset ids from a cookie and then needs to include all those assets in the page. The way I’m accessing the assets is by appending the asset id to a url eg. http://mypage?a=assetid. the assets then inherit the design from the parent.



I’m trying to include the assets in the page by using the <!–#include virtual="/mypage?a=assetid"–> but this doesn’t seem to work. Is there anyreason why this should not work?



I’ve also tried using the php include("/mypage?a=assetid") but that doesn’t work either as the pages I’m calling are outside of the php include directory.



The only thing that works is using an iframe and setting the src=“http://mypage?a=assetid” but i don’t really want to do that.



Any help would be appreciated, and if you have any suggestions for a better way to do this please advise me.



Cheers,

Geoff


(Daniel Nitsche) #2

Neither the SSI or php include methods you've mentioned should work in that manner – that's not what they were intended for.


Are you sure you need to create a custom asset? You could probably achieve something similar using a Related Asset Listing and tagging.


(Geoffrey Bailey) #3

I've built a customizable page where users can add any of our intranet pages to their own personal page and rearrange the content similar to iGoogle. It's all done client side though, which makes it a little bit slow. It would be great if the bulk of the processing could be done server side. Can you tell me why the include methods aren't working? Is it because I'm sending a parameter? I don't get any errors, the pages just don't get displayed.


(Avi Miller) #4

Matrix doesn't support SSI-style includes within content or using php includes in code to reference assets (as they are objects). Can you point me towards a URL where I can see this client-side solution? I'd like to see what it does before recommending options.

(Daniel Nitsche) #5

You can do something similar using an Access History design area, with two caveats: the links are lost when a user logs out (because the cookie is deleted), and you can't reorder links.

Includes (php and server side) normally work at the file system level, rather than using an URI. They required extra configuration to work remotely -- there should be more info on the php.net site.

(Geoffrey Bailey) #6

Ok thanks for the info.


(Geoffrey Bailey) #7

Another quick question. At the developer sessions I'm pretty sure there was a function somewhere that returns an assets contents when passed an asset id. Can anyone refresh my memory what this funtion is called and where it lives.


Cheers


(Greg Sherwood) #8

This code should get you the contents of an asset, without the design:

    $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset('1234');
    ob_start();
      $asset->printBody();
      $contents = ob_get_contents();
    ob_end_clean();


If you want the design too, change printBody() to printFrontend().

(Geoffrey Bailey) #9

Thanks Greg. I managed to figure out a way to do it

    $contents =& $GLOBALS['SQ_SYSTEM']->am->getAsset($assetId);
    echo "

" . $contents->getKeywordReplacement('asset_name') . "

"; echo $contents->getContent();


Is there a way to specify an alternate design though?

(Greg Sherwood) #10

Just be a little careful with that getContent() method. Not every asset implements it (it is for indexing content) and the output is not formatted like it would be on the frontend (i.e., no paint layout or designs).


As for the design, unless you call printFrontend(), no design will be painted when you get the content. Did you want to paint a design around the content before you use it?


(Geoffrey Bailey) #11

Is there a way to call an asset with a user defined design?


(Rayn Ong) #12

You can try this for a different design or layout, quite hacky though

    $am =& $GLOBALS['SQ_SYSTEM']->am;
    $page =& $am->getAsset(123);
    $design =& $am->getAsset(456);
    ob_start();
    	$design->paint($page);
    	$content = ob_get_contents();
    ob_end_clean();
    bam($content);


You probably can change $contents->getKeywordReplacement('asset_name') to just $contents->name?

(edited to add code tag)

(Geoffrey Bailey) #13

Thanks Rayn, I'll give it a try.