Jump to content

pointing to files using $config->urls->assets within a php tag


lecrackffm
 Share

Recommended Posts

Hello everyone,

this is my first post here, and i hope its the right place for my question.

I am getting started with PW and right now, im trying to bring a existing static Site to PW

In this static site i was working with some PHP to import svg code

echo file_get_contents("img/icons/ticket.svg")

I placed the img folder in the assets folder but now i am having troubles to point at this file using

$config->urls->assets

i was trying to do something like 

echo file_get_contents("$config-urls-assets/img/icons/ticket.svg")

but of course this fails and as i am not quite good with PHP i do not know how to nest this php to get what i want.

I don`t want to use fields to store the svg code, because i need different icons on one page and i do not want to create multiple field for that.

Any advice is highly appreciated.

Thank you.

Link to comment
Share on other sites

echo file_get_contents("{$config->urls->assets}img/icons/ticket.svg")

try this - the arrows are not complete and maybe wrap that into curly braces - and also you don't need the preceding slash! ;)

 

Oh, btw - you might like this? This is my placeSVG function which also strips the doctype and comments from svg files when embedded directly:

it assumes the templates/ directory as the standard location, but you can add an optional other path ['path' = ...] - and then it concatenates the path with the first argument

https://gist.github.com/blynx/d91d749e76c112f06a505a2d17dfdc2e

 

PS: Are you frankfurt (ffm) based? ^^

  • Like 3
Link to comment
Share on other sites

4 minutes ago, blynx said:

echo file_get_contents("{$config->urls->assets}img/icons/ticket.svg")

try this - the arrows are not complete and maybe wrap that into curly braces - and also you don't need the preceding slash! ;)

 

Thanks for the fast support!

oh sure, i forgot about the correct arrows writing my post.

The  curly brackets are giving me the correct path now, thanks for that.

I am  still i am getting a  

Warning: file_get_contents(/site/assets/img/icons/vibra.svg): failed to open stream: 

But the files are there for sure... ill figure that out..

Thanks for the fast support!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...