I’ve built a module that creates a new file from text between a tag pair, before creating the new file if a similar file already exists it moves it to an archive folder, it then writes the path for the new file back to the template.
I can send the file name back to be displayed in the template, this works fine, however as soon as I create a valid link to the new file and return or echo the new file path back to the template I have problems; the newly created file also gets copied to the archive folder, sometimes twice (the filename includes a timestamp, so sometimes it’s copied twice with a second difference).
Template tags:
{exp:custom_mod:test}
Some data.....
{/exp:custom_mod:test}
Module code:
public function test()
{
$page_data = ee()->settings_model->get_settings();
//fetch all files from folder
$directory = $page_data['folder_path'];
$pattern = "custom.*txt";
$files = ee()->file_model->folder_iterator($directory, $pattern);
//move existing to achive folder
ee()->file_model->move_to_archive($files);
//create new file and get link to it
$name = ee()->file_model->create_new_file();
$link_text = '<link href="' . $name . '" rel="stylesheet" >';
// this works as expected
return;
//this causes more than one new file to be created
return $link_text;
}
Have found that this only seems to happen with stylesheets, and if I remove ‘rel=”stylesheet” from the returned data the code behaves as expected.
What is happening?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.