Jump to content

Interactive Svg


Pavle
 Share

Recommended Posts

Hi all,

First of all, thank you (Ryan) for building this awesome CMS and thank you (nice people on this forum) for keeping this welcoming/helpfull community.

I recently found myself editing and changing .svg files to .inc files so I can include them with php, making them inline html elements, which allows me to use external css for manipulating them. Because doing this is sort of boring, and prune to mistakes (besides, it's much easier if one could just import svg file saved from illustrator), I started building a module which will take uploaded/submitted .svg file (using InputfieldFile) and:

1.) add user-defined class to group that is wrapping all elements

OR

2.) wrap all elements into a group and add a user-defined class

OR

3.) just strip all tags (doctype, ...) except SVG tag.

I have few problems and I am hoping you will be able to point me in the right direction:

1.) Why is original (.svg) file not saved on server (module output is saved instead, although with different extension)?

2.) How would I convince ProcessWire that it would render (only) those fields (that have this module enabled) as include("modified_file.inc");

so I could just write f.example: <div.icon><?php $page_with_icon->icon; ?></div>

3.) How come module's Boolean value in field's settings page is not saved, but text value (for class name) is?

I am also attaching my .module file.

Thank you for your help and please let me know, if I need to provide some additional information.

Thanks! =)

EDIT (30.7.2014):

So, I will answer my own questions, if somebody will have same problems in future =)
I solwed them like that:

1.) File was not saved, because there was an error in module that was not being reported.

2.) By using "$this->addHook("PageFile::includeSvg", $this, 'includeSvg');" where "includeSvg" is attached method. Method can now be used in templates with: $field->includeSvg(); 

3.) It seems it needs to be called separately in function that is defining additional config options (in my case it's "addConfig") as: 

$checked = $inputfield->makeInteractive == 1 ? "checked" : ""; $f->attr("checked", $checked);
 
I am attaching modified (working) module. 

interactiveSvg.module

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...