Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Convert Absolute URL to encodeurl Absolute URL


Go to End


1873 Views

Avatar
thomas.paulson

Community Member, 107 Posts

27 March 2014 at 8:41pm

Edited: 28/03/2014 12:15am

Magazine.ss
--------------------------
<% with $Magazine %>
<h1>$Title</h1>
<iframe src="http://docs.google.com/viewer?url={$Document.AbsoluteURL}&embedded=true" width="100%" height="842"></iframe>
<% end_with %>

if you check the above code, it print url as 'http://localhost/masapulari/assets/Uploads/dummy.pdf .
Magazine is a DataObject class and Document is File Type, as you see below.
Is there a way to print urlencode of $Document.AbsoluteURL?

class Magazine extends DataObject {

private static $db = array(
'Title'=>'VarChar',
'Date' => 'Date',
);

private static $has_one = array(
'Photo' => 'Image',
'Document' => 'File'
);

}

class Magazine_Controller extends Page_Controller {

/**
* An array of actions that can be accessed via a request. Each array element should be an action name, and the
* permissions or conditions required to allow the user to access it.
*
* <code>
* array (
* 'action', // anyone can access this action
* 'action' => true, // same as above
* 'action' => 'ADMIN', // you must have ADMIN permissions to access this action
* 'action' => '->checkAction' // you can only access this action if $this->checkAction() returns true
* );
* </code>
*
* @var array
*/
private static $allowed_actions = array (
'index','view'
);

public function init() {
parent::init();

// Note: you should use SS template require tags inside your templates
// instead of putting Requirements calls here. However these are
// included so that our older themes still work
Requirements::themedCSS('reset');
Requirements::themedCSS('layout');
Requirements::themedCSS('typography');
Requirements::themedCSS('form');
}

public function view(){
$params = $this->getURLParams();
$id = (int)$params['ID'];

$data = $this->Magazine($id);

return $this->customise(array(
'Magazine'=>$data
))->renderWith(array( 'Magazine', 'Page'));
}

public function Magazine($id){
$data = DataObject::get_by_id('Magazine',$id);
return $data;
}
}