<?php
$resid = $modx->resource->get('id');
$page = $modx->getObject('modResource', $resid);
return $modx->resource->getTVValue('mynumber');
Code: 200 OK Fatal error: Call to a member function get() on a non-object in /.../core/cache/includes/elements/modsnippet/100.include.cache.php on line 2
[[migxResourceMediaPath? &tvname=`identnr` &pathTpl=`assets/images/{tv_value}/`]] This question has been answered by Bruno17. See the first response.
<?php
/**
* @name migxResourceMediaPath
* @description Dynamically calculates the upload path for a given resource
*
* This Snippet is meant to dynamically calculate your baseBath attribute
* for custom Media Sources. This is useful if you wish to shepard uploaded
* images to a folder dedicated to a given resource. E.g. page 123 would
* have its own images that page 456 could not reference.
*
* USAGE:
* [[migxResourceMediaPath? &pathTpl=`assets/businesses/{id}/`]]
* [[migxResourceMediaPath? &pathTpl=`assets/test/{breadcrumb}`]]
* [[migxResourceMediaPath? &pathTpl=`assets/test/{breadcrumb}` &breadcrumbdepth=`2`]]
*
* PARAMETERS
* &pathTpl string formatting string specifying the file path.
* Relative to MODX base_path
* Available placeholders: {id}, {pagetitle}, {parent}
* &docid (optional) integer page id
* &createFolder (optional) boolean whether or not to create
*/
$pathTpl = $modx->getOption('pathTpl', $scriptProperties, '');
$docid = $modx->getOption('docid', $scriptProperties, '');
$createfolder = $modx->getOption('createFolder', $scriptProperties, false);
$tvname = $modx->getOption('tvname', $scriptProperties, '');
$path = '';
$createpath = false;
if (empty($pathTpl)) {
$modx->log(MODX_LOG_LEVEL_ERROR, '[migxResourceMediaPath]: pathTpl not specified.');
return;
}
if (empty($docid) && $modx->getPlaceholder('mediasource_docid')) {
// placeholder was set by some script
// warning: the parser may not render placeholders, e.g. &docid=`[[*parent]]` may fail
$docid = $modx->getPlaceholder('mediasource_docid');
}
if (empty($docid) && $modx->getPlaceholder('docid')) {
// placeholder was set by some script
// warning: the parser may not render placeholders, e.g. &docid=`[[*parent]]` may fail
$docid = $modx->getPlaceholder('docid');
}
if (empty($docid)) {
//on frontend
if (is_object($modx->resource)) {
$docid = $modx->resource->get('id');
}
//on backend
else {
$createpath = $createfolder;
// We do this to read the &id param from an Ajax request
$parsedUrl = parse_url($_SERVER['HTTP_REFERER']);
parse_str($parsedUrl['query'], $parsedQuery);
if (isset($parsedQuery['amp;id'])) {
$docid = (int)$parsedQuery['amp;id'];
} elseif (isset($parsedQuery['id'])) {
$docid = (int)$parsedQuery['id'];
}
}
}
if (empty($docid)) {
$modx->log(MODX_LOG_LEVEL_ERROR, '[migxResourceMediaPath]: docid could not be determined.');
return;
}
if ($resource = $modx->getObject('modResource', $docid)) {
$path = $pathTpl;
$ultimateParent = '';
if (strstr($path, '{breadcrumb}') || strstr($path, '{ultimateparent}')) {
$parentids = $modx->getParentIds($docid);
$breadcrumbdepth = $modx->getOption('breadcrumbdepth', $scriptProperties, count($parentids));
$breadcrumbdepth = $breadcrumbdepth > count($parentids) ? count($parentids) : $breadcrumbdepth;
if (count($parentids) > 1) {
$parentids = array_reverse($parentids);
$parentids[] = $docid;
$ultimateParent = $parentids[1];
} else {
$ultimateParent = $docid;
$parentids = array();
$parentids[] = $docid;
}
}
if (strstr($path, '{breadcrumb}')) {
$breadcrumbpath = '';
for ($i = 1; $i <= $breadcrumbdepth; $i++) {
$breadcrumbpath .= $parentids[$i] . '/';
}
$path = str_replace('{breadcrumb}', $breadcrumbpath, $path);
}
if (!empty($tvname)){
$path = str_replace('{tv_value}', $resource->getTVValue($tvname), $path);
}
$path = str_replace('{id}', $docid, $path);
$path = str_replace('{pagetitle}', $resource->get('pagetitle'), $path);
$path = str_replace('{alias}', $resource->get('alias'), $path);
$path = str_replace('{parent}', $resource->get('parent'), $path);
$path = str_replace('{context_key}', $resource->get('context_key'), $path);
$path = str_replace('{ultimateparent}', $ultimateParent, $path);
if ($template = $resource->getOne('Template')) {
$path = str_replace('{templatename}', $template->get('templatename'), $path);
}
if ($user = $modx->user) {
$path = str_replace('{username}', $modx->user->get('username'), $path);
}
$fullpath = $modx->getOption('base_path') . $path;
if ($createpath && !file_exists($fullpath)) {
$permissions = octdec('0' . (int)($modx->getOption('new_folder_permissions', null, '755', true)));
if (!@mkdir($fullpath, $permissions, true)) {
$modx->log(MODX_LOG_LEVEL_ERROR, sprintf('[migxResourceMediaPath]: could not create directory %s).', $fullpath));
} else {
chmod($fullpath, $permissions);
}
}
return $path;
} else {
$modx->log(MODX_LOG_LEVEL_ERROR, sprintf('[migxResourceMediaPath]: resource not found (page id %s).', $docid));
return;
}
[
{
"id":1,
"source":0,
"property_preprocess":false,
"name":"getImageList",
"description":"",
"editor_type":0,
"category":0,
"cache_type":0,
"locked":false,
"properties":[
],
"moduleguid":"",
"static":false,
"static_file":"",
"filename":"getimagelist.snippet.php",
"category_name":"MIGX"
},
{
"id":2,
"source":0,
"property_preprocess":false,
"name":"migxGetRelations",
"description":"",
"editor_type":0,
"category":0,
"cache_type":0,
"locked":false,
"properties":null,
"moduleguid":"",
"static":false,
"static_file":"",
"filename":"migxgetrelations.snippet.php",
"category_name":"MIGX"
},
{
"id":4,
"source":0,
"property_preprocess":false,
"name":"migx",
"description":"",
"editor_type":0,
"category":0,
"cache_type":0,
"locked":false,
"properties":null,
"moduleguid":"",
"static":false,
"static_file":"",
"filename":"migx.snippet.php",
"category_name":"MIGX"
},
{
"id":7,
"source":0,
"property_preprocess":false,
"name":"migxLoopCollection",
"description":"",
"editor_type":0,
"category":0,
"cache_type":0,
"locked":false,
"properties":null,
"moduleguid":"",
"static":false,
"static_file":"",
"filename":"migxloopcollection.snippet.php",
"category_name":"MIGX"
},
{
"id":34,
"source":0,
"property_preprocess":false,
"name":"migxResourceMediaPath",
"description":"",
"editor_type":0,
"category":0,
"cache_type":0,
"locked":false,
"properties":[ ],
"moduleguid":"",
"static":false,
"static_file":"",
"filename":"migxresourcemediapath.snippet.php",
"category_name":"MIGX"
},
{
"id":35,
"source":0,
"property_preprocess":false,
"name":"migxImageUpload",
"description":"",
"editor_type":0,
"category":0,
"cache_type":0,
"locked":false,
"properties":null,
"moduleguid":"",
"static":false,
"static_file":"",
"filename":"migximageupload.snippet.php",
"category_name":"MIGX"
},
{
"id":44,
"source":0,
"property_preprocess":false,
"name":"migxChunklistToJson",
"description":"",
"editor_type":0,
"category":0,
"cache_type":0,
"locked":false,
"properties":null,
"moduleguid":"",
"static":false,
"static_file":"",
"filename":"migxchunklisttojson.snippet.php",
"category_name":"MIGX"
},
{
"id":51,
"source":0,
"property_preprocess":false,
"name":"migxSwitchDetailChunk",
"description":"",
"editor_type":0,
"category":0,
"cache_type":0,
"locked":false,
"properties":null,
"moduleguid":"",
"static":false,
"static_file":"",
"filename":"migxswitchdetailchunk.snippet.php",
"category_name":"MIGX"
},
{
"id":52,
"source":0,
"property_preprocess":false,
"name":"getSwitchColumnCol",
"description":"",
"editor_type":0,
"category":0,
"cache_type":0,
"locked":false,
"properties":null,
"moduleguid":"",
"static":false,
"static_file":"",
"filename":"getswitchcolumncol.snippet.php",
"category_name":"MIGX"
},
{
"id":53,
"source":0,
"property_preprocess":false,
"name":"getDayliMIGXrecord",
"description":"",
"editor_type":0,
"category":0,
"cache_type":0,
"locked":false,
"properties":null,
"moduleguid":"",
"static":false,
"static_file":"",
"filename":"getdaylimigxrecord.snippet.php",
"category_name":"MIGX"
},
{
"id":59,
"source":0,
"property_preprocess":false,
"name":"filterbytag",
"description":"",
"editor_type":0,
"category":0,
"cache_type":0,
"locked":false,
"properties":null,
"moduleguid":"",
"static":false,
"static_file":"",
"filename":"filterbytag.snippet.php",
"category_name":"MIGX"
},
{
"id":88,
"source":0,
"property_preprocess":false,
"name":"migxObjectMediaPath",
"description":"",
"editor_type":0,
"category":0,
"cache_type":0,
"locked":false,
"properties":null,
"moduleguid":"",
"static":false,
"static_file":"",
"filename":"migxobjectmediapath.snippet.php",
"category_name":"MIGX"
},
{
"id":156,
"source":0,
"property_preprocess":false,
"name":"exportMIGX2db",
"description":"",
"editor_type":0,
"category":0,
"cache_type":0,
"locked":false,
"properties":null,
"moduleguid":"",
"static":false,
"static_file":"",
"filename":"exportmigx2db.snippet.php",
"category_name":"MIGX"
},
{
"id":161,
"source":0,
"property_preprocess":false,
"name":"preparedatewhere",
"description":"",
"editor_type":0,
"category":0,
"cache_type":0,
"locked":false,
"properties":null,
"moduleguid":"",
"static":false,
"static_file":"",
"filename":"preparedatewhere.snippet.php",
"category_name":"MIGX"
},
{
"id":168,
"source":0,
"property_preprocess":false,
"name":"migxJsonToPlaceholders",
"description":"",
"editor_type":0,
"category":0,
"cache_type":0,
"locked":false,
"properties":null,
"moduleguid":"",
"static":false,
"static_file":"",
"filename":"migxjsontoplaceholders.snippet.php",
"category_name":"MIGX"
},
{
"id":185,
"source":0,
"property_preprocess":false,
"name":"migxGetCollectionTree",
"description":"",
"editor_type":0,
"category":0,
"cache_type":0,
"locked":false,
"properties":null,
"moduleguid":"",
"static":false,
"static_file":"",
"filename":"migxgetcollectiontree.snippet.php",
"category_name":"MIGX"
},
{
"id":216,
"source":0,
"property_preprocess":false,
"name":"migxIsNewObject",
"description":"",
"editor_type":0,
"category":0,
"cache_type":0,
"locked":false,
"properties":null,
"moduleguid":"",
"static":false,
"static_file":"",
"filename":"migxisnewobject.snippet.php",
"category_name":"MIGX"
}
]
[ed. note: joe-petts last edited this post 10 years, 3 months ago.]
[[!pdoResources? &parents=`12` &tpl=`mytpl`]]
<div class="pic"> <img src="[[!lingua.getValue? &id=`[[+id]]` &field=`picture`]] "> </div>
<div class="pic"> <img src=""> </div>
<img src="assets/images/[[+tv.mynumber]]/[[!lingua.getValue? &id=`[[+id]]` &field=`picture`]] ">
[[!lingua.getValue? &id=`[[+id]]` &field=`picture`]]
[[!lingua.getValue? &id=`[[+id]]` &field=`mynumber`]]
[[!lingua.getValue? &id=`[[+id]]` &field=`picture`]]