By default, assets are placed in the site root as defined in the publishing settings. For example, if the site root was http://beausmith.com/
then the asset image.gif
would be uploaded to http://beausmith.com/image.gif
.
There are two common ways to change this:
- Define a default upload destination folder.
- Hard code upload destination and hide it from the form.
Define a default upload destination folder
To pre-populate the folder where assets will be placed add this line to the top of MT_BASE/tmpl/cms/include/asset_upload.tmpl
and replace “assets” with your preferred folder name:
<$mt:setvar name="extra_path" value="assets"$>
I use “assets” because this is the most generic word to describe all the things that could be placed in this folder: photos, video, documents etc.
Or the second way…
Hard code upload destination and hide it from the form
Open MT_BASE/tmpl/cms/include/asset_upload.tmpl
and search for this code (from MT4.0, code from MT4.1.x has a big chunk of javascript in the middle of the second <mtapp:setting>
block, but the javascript can safely be removed as well):
<mt:setvarblock name="upload_hint">
<__trans phrase="_USAGE_UPLOAD" params="<$mt:var name="blog_name" escape="html"$>">
</mt:setvarblock>
<mtapp:setting
id="folder"
label_class="top-label"
label="<__trans phrase="Upload Destination">"
hint="<$mt:var name="upload_hint"$>"
show_hint="1">
<!-- <$mt:var name="blog_url" escape="html"$> -->
<select name="site_path" onchange="setExtraPath(this)">
<option value="1"><<__trans phrase="Site Root">></option>
<mt:if name="enable_archive_paths">
<option value="0"<mt:if name="archive_path"> selected="selected"</mt:if>><<__trans phrase="Archive Root">></option>
</mt:if>
<mt:if name="extra_paths">
<mt:loop name="extra_paths">
<option value="<mt:if name="enable_archive_paths">0<mt:else>1</mt:if>" middle_path="<mt:var name="path" escape="html">"<mt:if name="selected"> selected="selected"</mt:if>><mt:var name="label" escape="html"></option>
</mt:loop>
</mt:if>
</select>
/ <input name="extra_path" id="extra_path" value="<mt:var name="extra_path" escape="html">" />
</mtapp:setting>
Replace the code with this code which will set the upload destination to <Site Root>/assets/
:
<input type="hidden" name="site_path" id="site_path" value="1" />
<input type="hidden" name="extra_path" id="extra_path" value="assets" />
The “Upload Destination” form elements should now be gone from the upload asset modal.
Note: There are other ways to do this in the Perl code. It’d be nice to just have config directives to handle this.