2

I have come up against an issue, and I want to check the best way to resolve this; here is a brief explanation.

So by default I have setup the craft assets folder to be called 'resources' and this lives in the top level of the website (although I think location is irrelevant). The client has now introduced a section called resources that has several child pages and a top level page. Which is accessed at /resources/ - I think the most sensible change is to rename my resources folder that holds all the uploaded assets. I will probably rename it uploads. However, what is the best approach to rename this without upsetting the system or having big issues.

I should also mention my resources folder also contains several sub folders for assets too.

2 Answers 2

4

You should be able to rename the directory on the server and then update the Asset Source settings changing the URL and system path. It should take care of it as Asset folders are stored relative to the top folder.

3

I usually use environment variables in the config.php to define paths to folders.

define('CRAFT_PUBLIC_PATH', realpath(dirname(__FILE__) . '/../') . '/public/');

return array(
    '*' => array(
        // ...
    ),

    'example.dev' => array(
        // ...

        'environmentVariables' => array(
            'basePath' => '...',
            'baseUrl'  => '...',
            'assetsPath'  => CRAFT_PUBLIC_PATH . 'assets',
            'assetsUrl'  => '/assets',
        )
    ),
);

You can then use the path in your twig templates:

{{ craft.config.environmentVariables.assetsUrl }}

And, if you define paths for Asset Sources, simply add the variable like this to the field:

{assetsPath}

This way, you can change the path easily at one place, after you had to rename a folder. The config is taken from: https://craftcms.com/docs/multi-environment-configs.

If you want to dig in deeper and make it completely right, I recommend following this advice (advanced): https://nystudio107.com/blog/multi-environment-config-for-craft-cms

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.