我已经为木材制作了自己的组件库(树枝文件)。在twig模板中包含路径是一个问题,因为我的库有树结构并且增长我想要包括像{%include" map-header" %}来自文件树的任何文件,我发现一些树,应该可以优先考虑。
现在我使用php函数搜索子目录中的twig文件并将其包含在{%include fn(' block',' map-header')%}
我目前的php功能:
function block($name){
$locations = array(
FRONTPATH.'app/blocks/site.blocks/',
FRONTPATH.'app/blocks/common.blocks/',
FRONTPATH.'app/blocks/ok.blocks/',
FRONTPATH.'app/blocks/base.blocks/'
);
foreach ($locations as $location) {
$path = realpath($location);
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)) as $filename)
{
$filename = str_replace(DIRECTORY_SEPARATOR,"/",$filename);
if(preg_match('/\/'.$name.'.twig/',$filename)){
return explode('/frontend/', $filename)[1];
}
}
}
返回; }
答案 0 :(得分:0)
多数民众赞成我的解决方案
import UIKit
class ViewController: UIViewController, UITableViewDelegate,
UITableViewDataSource, UIImagePickerControllerDelegate,
UINavigationControllerDelegate {
var objects = ["cup", "phone", "shoe", "tv"]
var images = [UIImage?](repeating:nil, count: 4)
var currentRow : Int = -1
var imagePicker : UIImagePickerController?
@IBOutlet weak var tableView: UITableView!
@IBAction func TakePhoto(_ sender: UIButton) {
imagePicker!.sourceType = .camera
self.currentRow = sender.tag
present(imagePicker!, animated: true, completion: nil)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return objects.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = Bundle.main.loadNibNamed("CustomTableViewCell", owner: self, options: nil)?.first as! CustomTableViewCell
cell.buttonOutlet.tag = indexPath.row
cell.buttonOutlet.addTarget(self, action: #selector(ViewController.TakePhoto(_:)), for: .touchUpInside)
cell.imageFound.image = images[indexPath.row]
return cell
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
guard self.currentRow != -1 else{
return
}
images[self.currentRow] = pickedImage
self.currentRow = -1
self.tableView.reloadData()
}
dismiss(animated: true, completion: nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
imagePicker = UIImagePickerController()
imagePicker?.delegate = self
}
}