base url for images in a package
Permalink
I am migrating a site to a C5 package and I wish to use the existing twig templates. To do so, I added the following twig() method to the page controller. report.php is just a standard twig template and ideally wouldn't have a PHP extension but C5 complains if it isn't. Then, I render to the C5 template page /twig which has a single line of code echo($html);.
It seems to work well enough, however, any recommendations are certainly welcomed. The reason I described how I am using twig is I expect there is a standard C5 way of doing what I will be asking next, but it might not work with my twig solution
I have all these images located in packages/my_app/images and the browser url is index.php/dashboard/report. How can I use the images without hardcoding some long absolute path?
Thanks
<?php class Report extends DashboardPageController { private $twig; public function view($id) { $this->twig('dashboard/report.php', $this->getData($id)); } //Actually, this is located in abstract parent protected function twig(string $template, array $variables=[], bool $render=true):string { if(!$this->twig) { $this->twig = new \Twig\Environment(new \Twig\Loader\FilesystemLoader(__DIR__.'/../single_pages'), [ 'debug'=>true, 'strict_variables'=>true ]);
Viewing 15 lines of 24 lines. View entire code block.
It seems to work well enough, however, any recommendations are certainly welcomed. The reason I described how I am using twig is I expect there is a standard C5 way of doing what I will be asking next, but it might not work with my twig solution
I have all these images located in packages/my_app/images and the browser url is index.php/dashboard/report. How can I use the images without hardcoding some long absolute path?
Thanks
Thanks linuxoid,
Felt kind of lazy and was hoping there was a single "defineBaseImageUrl()" method which would eliminate the need to edit each image src.
I also need to learn more about the app object as it seems to be a cornerstone of many needs. True? get_class_methods($this->app) provides the following
shutdown
dispatch
clearCaches
isInstalled
checkPageCache
handleAutomaticUpdates
setupPackageAutoloaders
setupPackages
setupFilesystem
isRunThroughCommandLineInterface
handleURLSlashes
handleCanonicalURLRedirection
environment
detectEnvironment
build
getRuntime
getRegisteredAliases
getRegisteredInstances
bindShared
when
bound
resolved
isAlias
bind
addContextualBinding
bindIf
singleton
share
extend
instance
tag
tagged
alias
rebinding
refresh
wrap
call
make
resolving
afterResolving
isShared
getBindings
forgetInstance
forgetInstances
flush
getInstance
setInstance
offsetExists
offsetGet
offsetSet
offsetUnset
__get
__set
Felt kind of lazy and was hoping there was a single "defineBaseImageUrl()" method which would eliminate the need to edit each image src.
I also need to learn more about the app object as it seems to be a cornerstone of many needs. True? get_class_methods($this->app) provides the following
shutdown
dispatch
clearCaches
isInstalled
checkPageCache
handleAutomaticUpdates
setupPackageAutoloaders
setupPackages
setupFilesystem
isRunThroughCommandLineInterface
handleURLSlashes
handleCanonicalURLRedirection
environment
detectEnvironment
build
getRuntime
getRegisteredAliases
getRegisteredInstances
bindShared
when
bound
resolved
isAlias
bind
addContextualBinding
bindIf
singleton
share
extend
instance
tag
tagged
alias
rebinding
refresh
wrap
call
make
resolving
afterResolving
isShared
getBindings
forgetInstance
forgetInstances
flush
getInstance
setInstance
offsetExists
offsetGet
offsetSet
offsetUnset
__get
__set
You can search for classes, properties, methods etc. here:https://documentation.concrete5.org/api/...
There is a method on the package object that gets the package dir.
The $img_url in view will be your relative path to the images folder: